Public inheritance
- The access properties of the base class's public and protected members remain the same in the derived class, but the private members of the base class are not directly accessible.
- member functions in derived classes can directly access public and protected members in the base class, but cannot access the private members of the base class directly.
- Objects derived from a class can access only the public members of the base class.
Private inheritance
- Both public and protected members of the base class appear in the derived class as private, but the private members of the base class are not directly accessible.
- member functions in derived classes can directly access public and protected members in the base class, but cannot directly access the private members of the base class.
- An object through a derived class cannot directly access any members in the base class.
Protect inheritance
- Both public and protected members of the base class appear in the derived class as protected, but the private members of the base class are not directly accessible.
- member functions in derived classes can directly access the public and protected members of the base class, but cannot directly access the private members of the base class.
- An object through a derived class cannot directly access any members in the base class.
Inheritance type \ access mode |
Public |
Protected |
Private |
Public |
Public |
Protected |
Private |
protected |
protected |
protected |
private |
Private |
Private |
Private |
Private |
Three ways of inheriting in object-oriented C + +