What is private inheritance?
- When a class is being derived from another class, we can make use of access specifiers. This is essentially useful to control the access the derived class members have to the base class.
- When inheritance is private :
i. Private members of base class are not accessible to derived class.
ii. Protected members of base class become private members of derived class.
iii. Public members of base class become private members of derived class.
using namespace std;
int i, j;
void setij(int a, int b)
i = a;
j = b;
cout <<”\nI:”<<i<<”\n J:”<<j;
class derived : private base
k = i + j;
//ob.setij(); // not allowed. Setij() is private member of derived
ob.setk(); //ok setk() is public member of derived
//ob.showij(); // not allowed. Showij() is private member of derived
ob.showall(); // ok showall() is public member of derived