You can derive a class from any number of base classes. Deriving a class from more than one direct base class is called multiple inheritance.
class A { /* ... */ };
class B { /* ... */ };
class C { /* ... */ };
class X : public A, private B, public C { /* ... */ };
The
following inheritance graph describes the inheritance relationships
of the above example. An arrow points to the direct base class of
the class at the tail of the arrow:The order of derivation is relevant only to determine the order of default initialization by constructors and cleanup by destructors.
class B1 { /* ... */ }; // direct base class
class D : public B1, private B1 { /* ... */ }; // error
class L { /* ... */ }; // indirect base class
class B2 : public L { /* ... */ };
class B3 : public L { /* ... */ };
class D : public B2, public B3 { /* ... */ }; // valid
B2::L
orB3::L.
You can also avoid this ambiguity by using the base specifier virtual to declare a base class, as described in Derivation (C++ only).