Declare f2 () virtual in the base class.
class a { public: void f1(); virtual void f2(); };
Then, whenever a derived class overrides f2() , a version will be called from the derived class itself, depending on the type of the actual object that the pointer points to, not the type of the pointer.
source share