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

Private Inheritance and Publice Inheritance

P: n/a
Hi,
Could someone here tell me some links/pdfs/tutorials to know about the
difference between Private Inheritance and Public Inheritance ?
I am unable to get info w.r.t it.

Thx in advans,
Karthik Balaguru

Sep 3 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
karthikbalaguru <ka***************@gmail.comwrote:
Could someone here tell me some links/pdfs/tutorials to know about the
difference between Private Inheritance and Public Inheritance ?
I am unable to get info w.r.t it.
http://www.parashift.com/c++-faq-lit...heritance.html
Sep 3 '07 #2

P: n/a
karthikbalaguru wrote:
Could someone here tell me some links/pdfs/tutorials to know about the
difference between Private Inheritance and Public Inheritance ?
I am unable to get info w.r.t it.
What book on C++ are you reading that doesn't explain the difference
and the use of access specifiers when deriving?

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

P: n/a
On Mon, 03 Sep 2007 10:19:45 -0700, karthikbalaguru wrote:
Could someone here tell me some links/pdfs/tutorials
to know about the difference between Private Inheritance
and Public Inheritance?
Inheritance always means "IS A" relationship.
E.g. "Porshe IS A Car".
It means that Porshe could do all the things that
all Cars can do.

Apply public inheritance when you want to describe
"IS A" relationshit to "whole world" ;) By writing
class Porshe : public Car
you say to everyone: "Porshe IS A Car".
Thanks to public inheritance, which defines that
kind of relationship, it's possible to use derived
class [i.e. the Porshe] in every place where the
Car is accepted, because every Porshe is also a Car ;)

Private inherintance could restrict the knowledge
about that family bonds only to the derived class.
The rest of the world will know nothing about that
relationship. The only thing which will be know that,
will be the class's implementation, and only it
will be able to use from that fact.

Some people also asks what is the difference between
private inheritance and composition. Some of them
sees no difference at all, because they focus only
on the fact that in both cases only the class's
implementation can use the contained/base class.
But there is one, very important difference:
overriding virtual methods. You cannot ovverride
a method of contained class, but you can do it
with methods of the [even privately] interface
derived from a base class.
--
SasQ
Sep 3 '07 #4

P: n/a
On Sep 3, 11:14 pm, "Daniel T." <danie...@earthlink.netwrote:
karthikbalaguru <karthikbalagur...@gmail.comwrote:
Could someone here tell me some links/pdfs/tutorials to know about the
difference between Private Inheritance and Public Inheritance ?
I am unable to get info w.r.t it.

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

Karthik Balaguru

Sep 4 '07 #5

P: n/a
On Mon, 03 Sep 2007 14:14:49 -0400, Daniel T. wrote:
http://www.parashift.com/c++-faq-lit...heritance.html
"(...)
The 'Car has-a Engine' relationship can also be expressed
using private inheritance:

class Car : private Engine
(...)"

WHAT?! o_O
What sense makes the above?
The "has-a" relationshit is evidently a composition.
If someone think different, let he try to think if
the Car could have more than one engine. I haven't seen
that kind of car, but if we do the same with the plane,
we'll see that it could have more engines than one.
How one could express that with use of [private] inheritance??
It's impossible, ant that's the reason why it should be
done with use of composition.

There is other thing wrong in that example.
It assumes that for the Car class's implementation
the Engine is an ancestor. So, from the perspective
of the implementation, Car is-a Engine [WTF?? LOL! :P].
I didn't know that a Car is a special kind-of-an
Engine, even if knowing that fact would be restricted
only for private interface of the Car class.
It's ridiculous!

I think the more adequate example would be:

class IllegalEmployee : private Employee

;D
The IllegalEmployee knows that he is a kind of Employee.
He is able to do what other legal employers do.
But for wider public he is not an Employee ;) He
doesn't confess that he is ;) Maybe some his friend
class EmployeesFriend [;D] could make use of this
fact, but not the others ;)

--
SasQ
Sep 4 '07 #6

P: n/a
And yet, private inheritance is sometimes called implementation
inheritance. It is equivalent to the composition with this
restriction: the relation must be one-to-one.

On 4 sep, 00:15, SasQ <sa...@go2.plwrote:
On Mon, 03 Sep 2007 10:19:45 -0700, karthikbalaguru wrote:
Could someone here tell me some links/pdfs/tutorials
to know about the difference between Private Inheritance
and Public Inheritance?

Inheritance always means "IS A" relationship.
E.g. "Porshe IS A Car".
It means that Porshe could do all the things that
all Cars can do.

Apply public inheritance when you want to describe
"IS A" relationshit to "whole world" ;) By writing
class Porshe : public Car
you say to everyone: "Porshe IS A Car".
Thanks to public inheritance, which defines that
kind of relationship, it's possible to use derived
class [i.e. the Porshe] in every place where the
Car is accepted, because every Porshe is also a Car ;)

Private inherintance could restrict the knowledge
about that family bonds only to the derived class.
The rest of the world will know nothing about that
relationship. The only thing which will be know that,
will be the class's implementation, and only it
will be able to use from that fact.

Some people also asks what is the difference between
private inheritance and composition. Some of them
sees no difference at all, because they focus only
on the fact that in both cases only the class's
implementation can use the contained/base class.
But there is one, very important difference:
overriding virtual methods. You cannot ovverride
a method of contained class, but you can do it
with methods of the [even privately] interface
derived from a base class.

--
SasQ

Sep 10 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.