Hi,
I have a question about definition of inheritance (perhaps as stated in C++
ISO docs somewhere).
Somebody claimed that when one class is derived from another, then the base
class' constructors and desctructors are inherited by the derived class.
Let's consider the simplest case:
class Base {};
class Derived: public Base {};
I tend to disagree and this is my argument:
The definition of inheritance (biologic, scientific, etc) states that it is
an acquisition of traits genetically transmitted from parent to offspring.
Well, in that case those traits in a parent are not modifiable by an offspring
in any way, only some of parent's "blueprint" is utilized in creation
of offspring's
"blueprint".
So, a derived class does not inherit constructors and desctructors of a base
class.
The purpose of inheritance is to create a condition for polymorphism
(an ability to substitute objects thru dynamic binding).
Constructors/destructors of a base class should not and can not be directly
exposed to a derived class to be possibly manipulated, e.g. hidden, overriden,
or overloaded.
This would lead to dynamic changes to the "blueprint" (which a base class is)
according to which instances (objects) are created.
The derived class may only automatically call the constructor and destructor
of a base class when it executes its own constructor or destructor, per
compiler setup, and not by user actions (programmatically, or any other way).
What is your opinion or that of official docs, if any ?
jb
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:
std-cpp...@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ:
http://www.comeaucomputing.com/csc/faq.html ]