If I have for example two classes A
and B
, such that class B
inherits A
as follows:
class B: public A
The "type" of inheritance depends on how the class is defined. There are default access specifiers applied to inheritance. From the C++ standard:
[class.access.base]/2
In the absence of an access-specifier for a base class, public is assumed when the derived class is defined with the class-key
struct
and private is assumed when the class is defined with the class-keyclass
. [ Example:class B { /* ... */ }; class D1 : private B { /* ... */ }; class D2 : public B { /* ... */ }; class D3 : B { /* ... */ }; // B private by default struct D4 : public B { /* ... */ }; struct D5 : private B { /* ... */ }; struct D6 : B { /* ... */ }; // B public by default class D7 : protected B { /* ... */ }; struct D8 : protected B { /* ... */ };
Here B is a public base of D2, D4, and D6, a private base of D1, D3, and D5, and a protected base of D7 and D8. — end example ]