/    /  CPP- Making a private member inheritable:

Making a private member inheritable:

 

A private member of a class cannot be inherited and, as a result, is not available for the derivative class directly. What happens if private data is to be inherited by a derived class? 

 

C++ provides a third, protected, visibility modifier for restricted inheritance use. A member declared protected is accessible by the functions of the member in his class and any class immediately deriving from it. It is not accessible by functions outside of both classes. 

 

A class is now able to use all 3 modes of visibility as shown below:

Class a
{
 private:
 int a;
- - - -
 Protected:
 int b;
- - -
 public:
 // members of the class
 }