If other, future classes derive from foo
in more than one way, then the most-derived class will contain only one, virtual base class bar
and kung
:
struct A : foo { };
struct B : foo { };
class Gizmo : public A, public B { }; // only *one* bar and kung base class.
An object of type Gizmo
has a unique base subobject of type bar
, and ditto for kung
, rather than two distinct ones for each derivation path.
Note that if a class has only pure-virtual functions and no non-static members and only base classes of the same nature, then there's no practical difference between virtual and non-virtual inheritance, since the classes are empty. Other, lesser languages call such classes "interfaces", meaning that it is OK to inherit from them multiply, even though such languages do not support multiple inheritance for general classes.