I have produced a minimal example to replicate the problem I am seeing with a more complex class hierarchy structure:
#include
#include
Currently your F
is derived from C
in two different ways. This means that an F
object has two separate C
bases, and so there are two instances of C::Print()
.
You only override the one coming via E
currently.
To solve this you must take one of the following options:
D
, either by implementing D::Print()
or F::Print()
Print
non-pureC
base.For the latter option, the syntax adjustments would be:
class E : virtual public C
and
class D : public B, public BB, virtual public C
This means that D
and E
will both have the same C
instance as their parent, and so the override E::Print()
overrides the function for all classes 'downstream' of that C
.
For more information , look up "diamond inheritance problem". See also Multiple inheritance FAQ