The following is a description of static variables in the class.
========================================================== ========
The usage and precautions of static data members are as follows:
1. When defining or describing static data members, add the keyword static.
2. static member Initialization is different from general data member initialization. The format of static data member Initialization is as follows:
<Data type> <class name >:< static data member name >=< value>
This indicates:
(1) initialization is performed in the external class without static before, so as to avoid confusion with general static variables or objects.
(2) during initialization, the access control letter private and public of the member are not added. Even if the static variable is private, it can still be initialized in the class in vitro (in fact, it can only be defined in the class in vitro), but it cannot be accessed in the main function. If it is not initialized, a link error may occur at the runtime.
(3) during initialization, the scope operator is used to indicate the class to which it belongs. Therefore, static data members are members of the class, not members of the object.
3. static data members are stored in static mode, which indicates the lifetime of static data and must be initialized.
4. When referencing static data members, use the following format:
<Class name >:: <static member name>
If the access permission of the static data member is allowed (that is, the Public Member), you can reference the static data member in the program in the preceding format.