* Busin:
When a child class inherits from a base class, will the child class inherits
everything of the base class, including all member variables and functions?
Or is such inheritance "selective", like not inheriting all constructors,
assignment operators, destructor, etc.? Thanks!
First, terminology: what you call a child class is in C++ called a
derived class, and more generally a subclass.
Yes, it inherits everything except those things you mention, namely
assignment operators, constructors and (with a high-level interpretation
of "inherit") destructors, but not everything is accessible
(accessibility depends on public/protected/private).
The reason constructors cannot be said to be inherited is that they're
not inherited.
The reason destructors cannot generally be said to be inherited is that
every class either defines its own destructor, or has one automatically
defined, or declares a destructor with no definition. But this is less
of a "no inheritance" than is the case with constructors. Depending on
what you mean by inheritance it's possible to argue that destructors are
in some cases inherited; for example, if class Base has a virtual
destructor, and class Derived does not define its own destructor, then
the implementation may choose to just use Base::~Base also for Derived
instead of actually definining a new destructor for Derived, and when
debugging a program at the source code level you will certainly not see
any Derived destructor being called, only the "inherited" Base one.
Also it's difficult to understand how a virtual destructor can be
overridden unless one thinks of it as inherited. But the terminology
adopted in the standard is one where a destructor is by definition not
inherited, but can be overridden -- I think it's just a mess...
The reason assignment operators are not inherited is that that would
play havoc with most classes. After all, most classes add data members.
Instead an assignment operator is automatically defined (roughly) if you
do not define or declare one yourself. But as with a virtual destructor
it's possible to argue -- with a more low-level view of "inherit" --
that virtual assignment operators can indeed be inherited. In
particular, without checking the standard on this, I think you can
override a virtual assignment operator, although such beasts are Evil.