2.1 Default Constructor Construction
The C++ Annotated Reference Manual (ARM) [ELLIS90] (Section 12.1) tells us that "default constructors…are generated (by the compiler) where needed…."
When is a default constructor synthesized, then? Only when the implementation needs it. Moreover, the synthesized constructor performs only those activities required by the implementation.
The Standard has refined the discussion in the ARM, although the behavior, in practice, remains the same. The Standard states [ISO-C++95] (also Section 12.1) the following:
If there is no user-declared constructor for class X, a default constructor is implicitly declared…. A constructor is trivial if it is an implicitly declared default constructor….
The standard then goes on to iterate the conditions under which the implicit default constructor is considered trivial. A nontrivial default constructor is one that in the ARM's terminology is needed by the implementation and, if necessary, is synthesized by the compiler.
There are four characteristics of a class under which the compiler needs to synthesize a default constructor for classes that declare no constructor at all. The Standard refers to these as implicit, nontrivial default constructors. The synthesized constructor fulfills only an implementation need. It does this by invoking member object or base class default constructors or initializing the virtual function or virtual base class mechanism for each object. Classes that do not exhibit these characteristics and that declare no constructor at all are said to have implicit, trivial default constructors. In practice, these trivial default constructors are not synthesized.
Within the synthesized default constructor, only the base class subobjects and member class objects are initialized. All other nonstatic data members, such as integers, pointers to integers, arrays of integers, and so on, are not initialized. These initializations are needs of the program, not of the implementation. If there is a program need for a default constructor, such as initializing a pointer to 0, it is the programmer's responsibility to provide it in the course of the class implementation.
Programmers new to C++ often have two common misunderstandings:
That a default constructor is synthesized for every class that does not define one
That the compiler-synthesized default constructor provides explicit default initializers for each data member declared within the class
As you have seen, neither of these is true.