Skip to main content

C++ Access Specifiers and Inheritance

C++ has three types of access specifiers public, protected and private. The below explanations assume that there are no friendship declarations are made between classes.

Public Inheritance

Public and protected members listed in base class keep there access specifiers in the derived class. Means public members of base class are public in derived class and protected members of the base class are protected in the derived class. Private members of the base class cannot be access in the derived class.

Protected Inheritance

Public and protected members listed in base class becomes protected members of the derived class. Private members of the base class cannot be access in the derived class.

Private Inheritance

Public and protected members listed in base class becomes private members of the derived class. Private members of the base class cannot be access in the derived class.

Also, please note if there is no access specifier defined in the base class all the members are private by default. If it is a struct the default will be public.