Download MetaTrader 5

Explicit call of constructor from within a constructor?

To add comments, please log in or register
Amir Yacoby
1174
Amir Yacoby  

Hi all,

Can you do it?

class a {};

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

    
Ex Ovo Omnia
3355
Ex Ovo Omnia  
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.
Amir Yacoby
1174
Amir Yacoby  
thx
whroeder1
16071
whroeder1  
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){}
Amir Yacoby
1174
Amir Yacoby  

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. 

To add comments, please log in or register