I have three different base classes:
class BaseA
{
public:
virtual int foo() = 0;
};
class BaseB
{
public:
virtual int foo() { return 42; }
};
class BaseC
{
public:
int foo() { return 42; }
};
I then derive from the base like this (substitute X for A, B or C):
class Child : public BaseX
{
public:
int foo() { return 42; }
};
How is the function overridden in the three different base classes? Are my three following assumptions correct? Are there any other caveats?
- With BaseA, the child class doesn't compile, the pure virtual function isn't defined.
- With BaseB, the function in the child is called when calling foo on a BaseB* or Child*.
- With BaseC, the function in the child is called when calling foo on Child* but not on BaseB* (the function in parent class is called).