By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Usage of private inheritance

P: n/a
Hi friends,

Can anybody answer me where exactly is the private inheritance is
used?
example:

class Base
{

public :

virtual int hello();
void fun();
};

class Derieved : private Base
{

public:

// lets hope some proto types are here

};

what is the usage of making a class inherit under private scope to
another class?

Rgrds
Murali

Jun 22 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"Indraseena" <mu**********@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi friends,

Can anybody answer me where exactly is the private inheritance is
used?
example:

class Base
{

public :

virtual int hello();
void fun();
};

class Derieved : private Base
{

public:

// lets hope some proto types are here

};

what is the usage of making a class inherit under private scope to
another class?

http://www.parashift.com/c++-faq-lit...heritance.html

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>
Jun 22 '06 #2

P: n/a

"Indraseena" <mu**********@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi friends,

Can anybody answer me where exactly is the private inheritance is
used?
example:

class Base
{

public :

virtual int hello();
void fun();
};

class Derieved : private Base
{

public:

// lets hope some proto types are here

};

what is the usage of making a class inherit under private scope to
another class?


Anything that derived from Derieved would not be able to see Base's public
items.
Jun 23 '06 #3

P: n/a
Jim Langston wrote:
"Indraseena" <mu**********@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi friends,

Can anybody answer me where exactly is the private inheritance is
used?
example:

class Base
{

public :

virtual int hello();
void fun();
};

class Derieved : private Base
{

public:

// lets hope some proto types are here

};

what is the usage of making a class inherit under private scope to
another class?


Anything that derived from Derieved would not be able to see Base's
public items.


Correction: making 'Base' private has the same effect as with any other
member of 'Derieved' that is private. Nobody except the *members* of
'Derieved' and its *friends* can access 'Base' part of 'Derieved'.

[Note: It was probably a typo in the original post, and both Jim's
and my intentions here not to support a wrong spelling of the word
'derived' but rather to follow the naming of the classes chosen by
the OP]

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 23 '06 #4

P: n/a
Hi,

I do agree that when we use private inheritance all the members
of the base call doesnt get inherited ar get private scope.
Then what is the use of inheriting that class. Will it come of some use
when using virtual Functions???

If I create a base class pointer then I will not be able to access the
features of the derived class I believe. So please answer me in this
perspective. I'm thinking it in this way. and looking in this part of
private inheritance usage.

Rgrds
Murali
Victor Bazarov wrote:
Jim Langston wrote:
"Indraseena" <mu**********@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi friends,

Can anybody answer me where exactly is the private inheritance is
used?
example:

class Base
{

public :

virtual int hello();
void fun();
};

class Derieved : private Base
{

public:

// lets hope some proto types are here

};

what is the usage of making a class inherit under private scope to
another class?


Anything that derived from Derieved would not be able to see Base's
public items.


Correction: making 'Base' private has the same effect as with any other
member of 'Derieved' that is private. Nobody except the *members* of
'Derieved' and its *friends* can access 'Base' part of 'Derieved'.

[Note: It was probably a typo in the original post, and both Jim's
and my intentions here not to support a wrong spelling of the word
'derived' but rather to follow the naming of the classes chosen by
the OP]

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Jun 26 '06 #5

P: n/a
Indraseena wrote:
I do agree that when we use private inheritance all the members
of the base call doesnt get inherited ar get private scope.
Then what is the use of inheriting that class. Will it come of some use
when using virtual Functions???

If I create a base class pointer then I will not be able to access the
features of the derived class I believe. So please answer me in this
perspective. I'm thinking it in this way. and looking in this part of
private inheritance usage.


I suggest you have a look at the C++ FAQ [1]. And, while you are at it,
be sure to check out this other document [2] as well.

[1] http://www.parashift.com/c++-faq-lit...heritance.html
[2] http://www.xs4all.nl/~hanb/documents/quotingguide.html

Regards,

--
Ney André de Mello Zunino
Jun 28 '06 #6

P: n/a

Victor Bazarov wrote:
[Note: It was probably a typo in the original post, and both Jim's
and my intentions here not to support a wrong spelling of the word
'derived' but rather to follow the naming of the classes chosen by
the OP]


Don't worry, we already know you never spell anything wrong.

Jun 28 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.