Re: What exactly is considered inherited from a base class? Organization: Roundhouse Consulting, Ltd.
On 12/05/11 01:06, Pete Becker wrote:
On 2011-05-11 12:07:28 -0400, Kris Prad said:
This is a Java site, yet applicable here:
http://download.oracle.com/javase/tutorial/java/IandI/subclasses.html
The site starts with a blanket statement like:
"A subclass inherits all the members (fields, methods, and nested
classes) from its super class." ---------------- (1)
and later on after a few paragraphs, narrows it down to:
=93Private Members in a Super class:
A subclass does not inherit the private members of its parent class.
However, if the super class has public or protected methods for
accessing its private fields, these can also be used by the subclass.=94
-------------- (2)
Umm, no. This talks about something that's fundamentally different from
the way that C++ works.
My question: Are private members of a base class considered inherited
or not? (That they are accessible via public accessor methods is
beside the point.)
My understanding: If the inheritance is conditional upon access ("data
hiding" aspect), then (2) is applicable - private members are not
inherited. Otherwise (1) is applicable. My understanding is that (2)
prevails. Data hiding and inheritance are orthogonal concepts in
theory, but bound together in practice. I may be wrong in interpreting
like this.
This may be splitting hairs as far as programming is concerned =96 one
just knows how they work, but the difficulty is in communicating these
as concepts.
In C++, all members are inherited. Try it. Write a base class with
private members that declares its derived class as a friend.
Personally I avoid using friend on the basis it defeats the whole point
of information hiding. IMHO the basis of object orientation is the idea
of a black box that performs some operation(s) controlled from defined
interfaces. How the black box operation(s) are actually implemented are
private.
With respect to inheritance, no friends, the public and protected
members of a base class are available to a descendent class. This also
holds true with respect to multiple level inheritance, hence only base
classes that have public or protected inheritance will be available to a
further descendent class, and only full public inheritance provides
global availability.
HTH
cpp4ever
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]