C++ philosophy
Split the problem into sets of classes. The resulting
hierarchy attempts to express the dependencies and
relationships between the components of the solution.
The process is non-trivial. Long after you have absorbed
the mechanics of C++, the design of a clean and rational
class hierarchy will remain a challenge! Once classes have
been designed, all that remains is to fill in the methods
The rise and fall of an object
Unlike simple scalarvariables (like an integer loop counter),
objects need to be created and removed explicitly (and with
some fuss).
Assume that an object is a non-trivial entity (all too true),
C++ lets us make implicit calls to helper functions to handle
the initialization and to clean up. These implicit calls are to
the constructorsanddestructorsof the class.
When an object is created, the system automatically
allocates enough memory to hold all its data members. It
then calls the provided constructor (or a default one if
necessary). The constructor function is called in the
context (framework, environment) of the emerging object.
|