Victor, With regard to your first question,
"What does "correctly" mean? I inherit from a class. I have no idea
how
it maintains its members, whether it has any dynamic memory management
or
not. Why should I care about it _at_all_?"
In the classic tome , "Advanced C++ Programming Styles and Idioms" ,
the renowned expert James O. Coplien writes "Programmers are
responsible for preserving the intuitive meaning of assignment in the
code they write; there is nothing in the language or compiler that will
force you to do what makes sense! To read why bitwise copy does not
work--and why even member-by-member copy does not always without some
help - see Appendix D,,,,,," I think James O. Coplien elegantly answers
your questions. 1) What does correctly mean? 2) Why care about it at
all? Please email me at
fr***********@hotmail.com if you want a copy of
Appendix D.
Finally , about the ARM ( 1st edition), you have to read between the
lines but in Chapter 12 , Section 8 Margaret Ellis and Bjarne
Stroustrup acknowledge that compiler generated copy constructors and
assignment operators in all classes , no matter whether they are base
or derived classes, should not always be used, "In practice, a good
compiler can generate bitwise copies for *most* class objects since
they have the bitwise copy semantics". Also , in the preface, Margeret
Ellis and Bjarne Stroustrup state "This C++ reference manual alone
provides a complete definition of C++, but the terse reference style
leaves many reasonable questions unanswered." So if you read the entire
manual in its entirety and implement and test copy constructors and
assignment operators for many base and derived classes following the
C++ language constructs described in the ARM, you will see why derived
classes should know how their base classes maintain their dynamic
memory.
For example, suppose you buy a 3rd party C++ library like
RogueWave. RogueWave provides you with the header files ( and source
code if you have the bucks) which show which private and protected
member variables
of their base classes use dynamically allocated library. Now, suppose
you don't care how their base classes implement their copy constructor,
default constructor, assignment operator and destructor and you
implement a class hierarchy based on RogueWave's base classes. Then,
one day, one of your customer calls up and tells you that your software
generates GP faults or leaks memory. After you look at your derived
classes and verify that the bug is not in the implenatation of your
derived classes, you have to ask RogueWave if the problem is in their
base class implementation. Since you paid RogueWave a lot of money to
buy their class framework, you have to ship RogueWave a whole bunch of
test code which help them determine whether you are using their base
classes correctly or whether they have to issue you a patch fix. I have
done this several times and I sure you have had to do the same thing
with the 3rd party libraries you have purchased. Regards , Frank