Explicit call of constructor from within a constructor?

Back to topics list To post a new topic, please log in or register
avatar
53
amir_avatar 2015.07.25 22:59
 

Hi all,

Can you do it?

class a {};

class b : public a
 {
  b(int i):this("explicit call") 
   {
   }
  b(string s)
   {
    str=s;
   }
  }

    
avatar
1109
Ovo 2015.07.25 23:10 #
 
I bet it is much faster to try yourself than waiting for an answer here. You cannot. You can create a (private) function that gets invoked from both constructors. No this(), no super() in MQL.
avatar
53
amir_avatar 2015.07.26 02:42 #
 
thx
avatar
13001
WHRoeder 2015.07.26 13:55 #
 
For super I use this pattern
class Shared_Pointer_Subscriber : public Shared_Pointer{
#define Shared_Pointer_Subscriber_SUPER Shared_Pointer
 public:
   void     Shared_Pointer_Subscriber(Subscriber* subscriber)           // Ctor
                               : Shared_Pointer_Subscriber_SUPER(subscriber){}

avatar
53
amir_avatar 2015.07.26 14:52 #
 

I wanted to call another constructor in the same class, not in super class.

WHRoeder, I didn't understand what you are trying to show.

From what I understand, you are calling the super constructor in Shared_Pointer.

I asked for different thing but still interesting, why are you using the constant for the super class name? Isn't it the same with the actual super class name (Shared_Pointer) instead the precompiler constant?

 

Thanks. 

Back to topics list  

To add comments, please log in or register