Generic pointer to access subclass methods

 

I tried to use generic pointers to access the subclasses methods but I was unable to access the correct methods. 

Can you help me to do it right?

I expected the direct and indirect access with the same output.

class Super {
public:
   void action(){ Print("Super");}
};

class A : public Super {
public:
   void action(){ Print("A");}
};

class B : public Super {
public:
   void action(){ Print("B");}
};

void action(){
   Super* s = new Super();
   A* a = new A();
   B* b = new B();
   
   Print("Using direct access with right pointer type");
   s.action();
   a.action();
   b.action();
   
   Super* arr[3];
   arr[0] = s;
   arr[1] = a;
   arr[2] = b;
   
   Print("Using indirect access with the generic pointer type");
   for(int i=0;i<3;i++) arr[i].action();
}

/* OUTPUT
2018.08.31 10:37:40.994 2018.08.22 00:00:00   Using direct access with right pointer type
2018.08.31 10:37:40.994 2018.08.22 00:00:00   Super
2018.08.31 10:37:40.994 2018.08.22 00:00:00   A
2018.08.31 10:37:40.994 2018.08.22 00:00:00   B
2018.08.31 10:37:54.379 2018.08.22 00:00:00   Using indirect access with the generic pointer type
2018.08.31 10:37:54.379 2018.08.22 00:00:00   Super
2018.08.31 10:37:55.881 2018.08.22 00:00:00   Super
2018.08.31 10:37:56.631 2018.08.22 00:00:00   Super
*/
 
https://www.mql5.com/en/docs/basis/oop/virtual
Documentation on MQL5: Language Basics / Object-Oriented Programming / Virtual Functions
Documentation on MQL5: Language Basics / Object-Oriented Programming / Virtual Functions
  • www.mql5.com
The virtual keyword is the function specifier, which provides a mechanism to select dynamically at runtime an appropriate function-member among the functions of basic and derived classes. Structures cannot have virtual functions. It can be used to change the declarations for function-members only. A virtual function may be overridden in a...
 
Alain Verleyen:
https://www.mql5.com/en/docs/basis/oop/virtual
Tks a lot!
Reason: