Private Inheritance

What is Private Inheritance? Give its syntax?

Questions by sidra siddiqui

Showing Answers 1 - 6 of 6 Answers

snigdha1

  • Jun 4th, 2010
 

Private Inheritance makes all of the public functions of the parent class private in child class. They can be used in order to implement child class without being accessible to outside world.

Syntax: same as public inheritance

Ex: class car:public Vehicle
{
public:
.....
};

here car is derived from Vehicle

  Was this answer useful?  Yes

Private Inheritance is inheriting a (base) class, privately, making all members of Base class, private in derived class. In that case, no objects of derived class OR any member of derived of derived class can access any member function or data of Base class.

Ex:

class B {
private:
int a;
public:
void f1();
}

class D1 : private B {
...
}

class D2 : public D1 {
private:
void f_d2_1();
public:
void f_d2_2();
...
}

In this Ex, D1 is Private inheritance of class B, so NO object of D1 can call f1() or can access int a.
Similarly, no object of D2, or functions f_d2_1() or f_d2_2() can access a or f1().

In other words, in case of private inheritance, the members of base class, ACT like PRIVATE MEMBERs of derived class, for the objects or subsequent derivations of Derived class.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions