473,804 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4413
karthikbalaguru <ka************ ***@gmail.comwr ote:
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...@earth link.netwrote:
karthikbalaguru <karthikbalagur ...@gmail.comwr ote:
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.plwr ote:
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
12822
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 below *should* happen, but my question to the community is *why* does it happen? Any answer will be appreciated, but a section and paragraph number from the C++ Standard would be especially appreciated.
3
2945
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 define destructor as "private/protected"? Thanks!
10
2496
by: Ioannis Vranos | last post by:
May someone explain why does this compile? class HiddenSealBaseClass { public: HiddenSealBaseClass() { } }; class Sealed: virtual HiddenSealBaseClass
2
2523
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 'class base *' exists, but is inaccessible" If I inherit using public it works well ... I am not very clear about the private inheritance
1
448
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 having private inheritance then when you have public inheritance. I just want to have you opinion about this matter.
8
7832
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 scope they meant public/protected/private access modifiers :) Obviously all members of the base privately inherited class will be private, and that was my answer. However, the teacher checked my answers when I handed in, and the problem was that I had...
8
2042
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 never seen it in a commercial code. If someone did, please share the use-case and decisions behind it. Thanks
13
1736
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 up with this: //base private object constructor function priv(){ this.a = 1; this.b = 2;
4
1821
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 following program can not pass compiling , bailing : g++ d.cpp -o d d.cpp: In function `int main()': d.cpp:27: error: `a' is an inaccessible base of `b' it is obviously okay to understand,because private inheritance is-
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.