Calling an overridden function on the child class

What you want is to use polymorphism. It’s not clear whether or not your variable MySelectedElement is a pointer or not. Your variable needs to be a pointer to the base class in order to use polymorphism.


ParentClass * MySelectedElement;

MySelectedElement = new childA;
MySelectedElement->Func1(); //this will call childA::Func1

delete MySelectedElement;

MySelectedElement = new childB;
MySelectedElement->Func1(); //this will call childB::Func1


So what you want to do is store a pointer to the base class. Then you can allocate any child class and assign it to that base class pointer. You can call any functions defined in the base class, and if those functions are overridden in the child class, the child class functions will be called instead of the base class functions.