Download MetaTrader 5
To add comments, please log in or register
Add our Twitter channel to friends and follow the news!
Amir Yacoby
Amir Yacoby 2015.06.13 12:51 


I have a class that holds a dynamic array of pointers to types of subclass of another base class.
It has a method that accepts a reference to a certain type of the subclass and I need to know if 
it already has a saved pointer to that type of subclass.

Is there a way doing it by the pointer type and without adding a type property to each subclass?

whroeder1 2015.06.13 16:37  
Since up casting to an improper type aborts the EA, and MT4 doesn't have any dynamic cast or RTTI, I implemented my own.
class B : public Polymorphic{ POLYMORPHIC(Polymorphic);
 ... };  // B
class D : public B{ POLYMORPHIC(B); //<< Base bracket P() is private.
... };   // D
class E : public B{
     POLYMORPHIC(B);                //<< Base over Base shows names match.
... };   // E
   B* bp = new D();
   D* dp; if(bp.dynamic_cast(dp)){     // bp is a D and returns true.
   E* ep; if(bp.dynamic_cast(dp)){     // bp is not a E and returns false.
To add comments, please log in or register