Sign in to follow this  
Tibetan Sand Fox

Is there any practical use of private inheritance ?

Recommended Posts

Hello there.

 

As asked in topic I wonder if there is any sense of using private inheritance as this:

 

class Foo
{

public:
    void Bar();
};

class Derived : private Foo
{
};

 

 

pretty much means the same as that:

class Foo
{

protected:
    void Bar();
};

class Derived : public Foo
{
};

 

Only difference I see is that I choose if I want public elements of Foo class to be inherited as private or if I'd rather like to inherit them as public, but is that flexibility helpful in any way ? I mean, in my opinion private inheritance could possibly just bring mess and chaos to code, but maybe some people in here had an occasion to find that solution helpful ? Thank you very much in advance.

Share this post


Link to post
Share on other sites
Thank you very much for the answers. That's just what I needed to know. I did some research on my own about the private inheritance and I found quiet few more of the uses of that feature. Actually I could have done that before asking the question, but well, without the questions forum would be quiet empty happy.png

//edit: +1'ed as promised. Edited by Agbahlok

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this