Chapter 4 class 12.4.1 constructor Initialization
1. the only opportunity to initialize a const or referenced data member is in the constructor initialization list.
2. In the constructor initialization list, it is best to initialize members in the initialization Order declared by each member variable in the class. Otherwise, an uninitialized member variable will be used to initialize another member variable. Of course, we should try to avoid using member variables to initialize other member variables.
12.4.2 the constructor is involved by default.
1 It is best to provide a default real parameter when constructing a function.
12.4.3 default constructor
1. The default constructor for merging uses the same rule as the variable initialization to initialize its internal members.
Members of the two types of internal classes are initialized through their Default constructors.
3. Built-in and composite Members, such as pointers and arrays. Class objects are initialized only when they are defined as global scopes. If the objects are defined as partial scopes, built-in and composite Members are not initialized.
4. Each constructor should provide initialization for each built-in or composite member. Constructors that do not initialize built-in or composite Members will put those members in undefined state.
5 if you do not initialize these Members, it is wrong to use an undefined member in any way except as the value assignment target. Therefore, it is best to use the constructor to set a clearly known state for each member so that no error will occur.
12.6.1 static class member
1. Unlike common data members, static data members exist independently of any objects of the class. Each static data member is an object associated with the class and is not associated with the objects of the class.
2. Using static members instead of using global objects has three advantages:
1) The static member name is in the scope of the class, so it can avoid conflicts with other class members or global object names.
2) encapsulation can be implemented. Static members can be private members, but global objects cannot.
3) through the reading program, it is easy to see that static members are associated with specific classes. This visibility clearly shows the programmer's intent, that is, the code is clear.
3 static
A member function is a component of a class but not a component of any object. Static member functions do not have the this pointer. This function can directly access static members of the class, but cannot directly use non-static members.
4. The static member may be directly called from the class through the scope operator, or indirectly called through an object, reference, or pointer to an object of this type.
5 static data members must be defined externally in the class definition body. It is not initialized through the class constructor, but should be initialized during definition.
6. A non-static data member cannot be used as the default real parameter because its value cannot be used independently of the object to which it belongs. If a non-static data member is used as the default real parameter, an object cannot be provided to obtain the value of the member. Therefore, it is incorrect.
Class 7 static member functions can use non-static data members of the class object metadata class.