Pls help me in understanding private inheritance...!!

first am tryin to build a class with constructor defined in private access specifer as below...

class Privt
{
private:
Privt(){cout<<"in const with addr: "<<this<<endl;}
~Privt(){cout<<"in dist with addr: "<<this<<endl;}
};
main()
{
Privt PP;
}

This will obviously show errors..This means we wont be able to create object with constructor defined in private...

Now for the below inheritance::

class Privt
{
public:
Privt(){cout<<"in const with addr: "<<this<<endl;}
~Privt(){cout<<"in dist with addr: "<<this<<endl;}
};

class Dprivt: private Privt
{
public:
Dprivt(){cout<<"in derived with addr: "<<this<<endl;}
~Dprivt(){cout<<"in derivd dist addr: "<<this<<endl;}
};

main()
{
Privt pp;
cout<<endl;
Dprivt dpp;
cout<<endl;
}

The output will be as below::

in const with addr: 0x22ff50

in const with addr: 0x22ff40
in derived with addr: 0x22ff40

in derivd dist addr: 0x22ff40
in dist with addr: 0x22ff40
in dist with addr: 0x22ff50




Now my understanding of private inheritance is that all the public members will be private for inherited class if this is happening how is it am able to create object of derived class because the constructor of base class will be in private for private derived class Dprivt...
closed account (S6k9GNh0)
http://www.cplusplus.com/doc/tutorial/inheritance/
There is a difference between "private inheritance" and "inheriting private members".
Topic archived. No new replies allowed.