My question is likely to be best explained by example.
For example, I have 2 classes: a base class and a derived class:
class baseClass
{
public:
baseClass()
{
foo();
}
virtual bool foo() { printf("baseClass"); return false;}
};
class derivedClass : public baseClass
{
public:
bool foo()
{
printf("derivedClass");
return true;
}
};
When I create an instance derivedClass, the constructor in will be called baseClass, and from it will be called foo(). The problem is that the baseClass constructor calls its own foo()and not overridden foo(), which overrides the derived class. Is there a way to force baseClass to call an overridden function, rather than a function definition itself?
source
share