I want to call an overridden method from a base class method called by a derived class:
class Base { Base(); virtual void function override() {} void basefunction() { override(); } class Derived : public Base { Derived() { basefunction(); } virtual void function override() { cout << "derived" << endl; } } main() { Base* d = new Derived(); }
The Derived constructor calls the base function, which must call the overridden function "override()" from the derived class.
But this is not so. It calls Base :: override (). I understand why this function is called, but how can I implement my problem that the base function calls the override function from the derived class?
If the override function is defined as pure virtual, the declaration in the main function is not allowed.
source share