473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Private Inheritance and Publice Inheritance

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
6 4389
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error...
3
by: seesaw | last post by:
Compared to "public", how does "private/protected" in inheritance change relationship between classes what is the purpose to define constructor as "private/protected"? is there any usage to...
10
by: Ioannis Vranos | last post by:
May someone explain why does this compile? class HiddenSealBaseClass { public: HiddenSealBaseClass() { } }; class Sealed: virtual HiddenSealBaseClass
2
by: MJ | last post by:
Hi I have a following sample code class base and class derived. I have inherited the base class as private and tried to compile the code its giving an error "conversion from 'class derived *' to...
1
by: Tony Johansson | last post by:
Hello! Private inheritance is sometimes called implementation inheritance. If you use this private inheritance how is with the usage of overriding then. Is overriding used less often when...
8
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By...
8
by: puzzlecracker | last post by:
The statement is taken from FAQ . What about non-virtual functions? Can they be overriden? I still don't see a good justification to prefer private inheritance over composition. In fact, I have...
13
by: PragueExpat | last post by:
I (think) that I've come up with a pattern that I haven't seen in any publications so far and I would like some feedback. Basically, I was looking for a way to inherit private functions and I came...
4
by: zhangyefei.yefei | last post by:
i read book <effective c++>,it tell me that public inheritance means is-a ,and private inheritance means is-implemented-in-terms-of. but today i am puzzled by some strange codes. the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.