Remember:
For anything other than the built-in type, the initialization responsibility falls on the constructor, ensuring that each constructor initializes each member of the object.
C + + stipulates that the initialization action of a member variable of an object occurs before entering the constructor body.
Replace the assignment action within the constructor with the member initialization list.
If the member variables are const or reference, they must have an initial value and cannot be assigned.
The base class is initialized earlier than derived class, and the member variables of class are always initialized in the order in which they are declared, not affected by the order of the member initialization list.
To avoid the "initialization order across compilation units" issue, replace the non-local static object with the local static object.
Abentry::abentry (conststringconststring& address, Const list<phonenumber>& phones) : thename (name), theaddress (address), thephones ( Phones), numtimesconsulted (0) { = name; // These are assignments, not initialization theaddress = address; = phones; 0 ;}
Abentry::abentry (conststringconststring& address, Const list<phonenumber>& phones) : thename (name), theaddress (address), thephones ( Phones), numtimesconsulted (0) {}
abentry::abentry () : Thename (), // Call the default constructor of Thename Theaddress (), thephones (), numtimesconsulted (0) {}
Effective C + + clause 04: Determine that an object was initialized before it was used