Download MetaTrader 5
To add comments, please log in or register
Have you found an interesting application? Publish it in Code Base - millions of traders will appreciate that!
Bogdan Tenea
200
Bogdan Tenea 2012.03.19 21:39 

"You can use the explicit casting to convert the base class pointers to the pointers of a derived class. But you must be fully confident in the admissibility of such a transformation, because otherwise a critical runtime error will occur and the mql5 program will be stopped."

 Is there any way to check what kind of object type I am using - for example get the class name ? I wish to be able to do this to see I am casting to the right type of object a base class. For example in java you have the "getClass" method :)

dck
70
dck 2012.08.06 17:43  

You are right, a getClass() method would be usefull.

Ovo Cz
3046
Ovo Cz 2014.06.11 11:51  

Besides the explicit typecasting there is undocumented implicit typecasting, too.

Considering it is rather unique feature neither used in C++ nor JAVA, I wonder how stable it is. I mean, if I coded using implicit casting, would I get a surprise with subsequent compiler versions?

 The following code compiles, so far.

void OnStart() {
   B* x = new B();
   // compiles OK without explicit typecasting
   A* a = x.getO(); 
   B* b = x.getO();
   C* c = x.getO();
}

class O {
};

class A: public O {
};

class B: public O {
public:
   O* getO() {return new O();}
};

class C: public O {
};
/
To add comments, please log in or register