x

C++ Inheritance Access Control

PREV     NEXT

C++ Inheritance Access Control:


What is inheritance access control?

  • When creating a derived class from a base class then, you can use different access specifiers to inherit the data members of the base class.
  • The derived class can access all the non-private members of its base class. And the base class members that are not accessible to the member functions of derived classes should be declared private in the base class.
  • The access specifiers that are used are public, private and protected.
  • When deriving a class from a base class, the base class may be inherited through public, private and protected inheritance.

Let us have a brief description about these specifiers:

Public Inheritance:

When inheriting a class from a public parent class, public members of the parent class become public members of the child class and protected members of the parent class become protected members of the child class.


The parent class private members cannot be accessible directly from a child class but can be accessible through public and protected members of the parent class.

Private Inheritance:

When we derive from a private parent class, then public and protected members of the parent class become private members of the child class.

Protected Inheritance:

When deriving from a protected parent class, then public and protected members of the parent class become protected members of the child class.

Let us have a look at the example:



Like it? Please Spread the word!