My question will probably be best explained by an 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 of derivedClass
, the constructor in baseClass
will be called, and foo()
will be called from it's constructor. The problem is, the baseClass' constructor is calling its own foo()
and no the overridden foo()
that the derived class has overridden. Is there anyway to make the baseClass call the overridden function, not it's own definition of the function?