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.
Files:
polymorphic.mqh
6 kb

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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?