1. Use constructors to ensure initialization
The client programmer must call the structure of the initialization object before using the object, but they tend to forget it, which can be left to the library programmer for Automatic processing. This is the constructor. The name of the function is the same as the name of the class, and the compiler can recognize it.
2. Use destructors to ensure cleanup
Constructors and destructors are not return values, and the void return value differs from the general void function, and he cannot do anything else. When object creation is an automatic call to a constructor, the destructor is called automatically when the object is outside its scope. Non-localized goto statements do not call destructors, but sometimes the compiler does not support them.
3. Clear the definition block
In C, it is always necessary to define all the variables at the beginning of the program block, C + + to ensure that an object is generated and initialized at the same time, but at first it is difficult to know all of the initialization information, C, the first definition but there is no initialization method is a bad practice. In general, the rules that apply to an object in C + + also apply to internal objects, which means that C + + typically waits for all information about an object to be defined, defined, and initialized together. In standard C99, you can also define a variable anywhere in a block. Facts for internal variables, for forward compatibility, most compilers allow variables to be initialized at the beginning of the definition.
6th Chapter Initialization and cleanup