First, static member variables and static member functions
1. Common member variables each object has its own copy, and the static member variable is one copy, shared for all objects
2. Ordinary member functions must be specific to an object, whereas static member functions do not specifically work on an object.
3. Therefore, static members do not need to be accessible through objects
4. Static member variables are essentially global variables, and even if an object does not exist, the static member variable of the class exists. A static member function is essentially a global function.
5. Set static members The purpose of this mechanism is to write global variables and functions that are closely related to certain classes into the class, looking like a whole, easy to maintain and understand.
Attention:
1. A static member variable must be described or initialized in the file that defines the class, or the compilation will pass, but the link will not pass.
2. In a static member function, you cannot access a non-static member variable or call a non-static member function.
C + + basic syntax