1. For a built-in type, if the variable is defined in the global scope, the default is initialized to 0, and if the variable is defined within the local scope, the default is not initialized;
For class types, the default constructor is called to initialize by default, and if there is no default constructor, it must be explicitly initialized.
2. Constructors ' initialization of a member occurs in the initialization list rather than in the body of the function, and the "initialization" in the function body is actually an assignment, and for class types, it reduces the efficiency of the program, which has no effect on the efficiency of the built-in type in the initialization list or in the function body, but in some special cases ( For example, const variables and references) must be initialized in the initialization list.
3. Constructors for class types are initialized in the order of members by: base class member → derived class class type members (in declaration order) → derived class built-in type members (in order of declaration).
4. For multi-file programs, "C + + for non-local static objects defined in different compilation units" (Static object refers to "life from being constructed to know the end of the program" object, including the global object, defines the object within the domain namespace, Within the class, within the function, and objects declared as static within the scope of the file, the static object within the function is called the local static object, and the initialization order of other known non-local static objects is not explicitly defined. Therefore, if the initialization of a non-local static object within a file is determined by the value of one of the non-local static objects in another file, because their initialization order is not explicitly defined, then the latter may be issued by the former before being initialized. , one of the workarounds is to place the Non-local static object inside the function (the object is declared static), which returns a refrence point to the object it contains, and then the user calls these functions instead of directly involving them, that is, using the local The static object replaces the Non-local static object, which is based on the fact that the C + + guarantee that the local static object within the function will be "the first time that the function is called" "the definition of the object" is initialized. Thus, it is guaranteed that the reference obtained by the calling function will necessarily point to an already initialized object.
Note: For static objects, there is a slight difference in the definition of different places (the main focus is on whether the global object is a static object, and from the lifetime, the lifetime of the global object is the same as the lifetime of the static object, from a scope perspective, The following two addresses can deepen the understanding of scopes and static objects as global objects work on multiple files and objects declared as static within a file scope are used only for this file):
Http://www.jb51.net/article/41324.htm
http://blog.csdn.net/liuqiaoyu080512/article/details/8455707
Effective C + + clause 4 determines that an object has been initialized before it is used