Check type of subclass

Back to topics list To post a new topic, please log in or register
avatar
53
amir_avatar 2015.06.13 14:51
 

Hi,

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?

 

 

avatar
12992
WHRoeder 2015.06.13 18: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.
 public:
... };   // 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.

Attached files:
  polymorphic.mqh  (5.05 KB)
Back to topics list  

To add comments, please log in or register