C++ Inheritance

Suppose we obtained a class B as derived from a base class A. The inherited members by the class B are filtered by the class A and become as follows:

Inher. type Class member types
private
  • Private members of A are inaccessible
  • Protected members of A become private members of B
  • Public members of A become private members of B
protected
  • Private members of A are inaccessible
  • Protected members of A become protected members of B
  • Public members of A become protected members of B
public
  • Private members of A are inaccessible
  • Protected members of A become protected members of B
  • Public members of A become public members of B

In other words, the members access modifies as follows:

Base class Inheritance Derived class
private: X
protected: Y
public: Z
private X is inaccessible
private: Y
private: Z
private: X
protected: Y
public: Z
protected X is inaccessible
protected: Y
protected: Z
private: X
protected: Y
public: Z
public X is inaccessible
protected: Y
public: Z

The public and private inheritance is schematically shown on the following picture