A static member of a class, which is shared by all objects, is allocated at the start of the process, and is then fixed without allocating space.
The difference between a static member variable of a class and a global variable outside the class is that you can set an access flag to allow only object access to the class. If you define static variables for public in a class, then there is no difference between a global variable and a class.
And what about the variables defined in a static member function of a class? Is it also shared by all objects?
The static function of a class is the same as a member variable of a class, and it is when the process executes that the control is assigned to the code at the outset, and then provides a function's address entry for all objects or other code calls, and static functions are not allowed to invoke the class's normal variables. You can only access static variables for a class. Because it does not get the this pointer to the object. The advantage of static function is that it can be invoked directly with the class name dot, without having to allocate space to generate an instance object.
Each time the static function is invoked, the process also presses it into the stack and allocates a space within the stack for the variables defined in the static function, each time the static function is invoked, the local variable of the static function is assigned.
So the variables defined in the static function are independent,
What if a static variable is defined in a static function? The fact tells us that static variables are not allowed to be defined in static functions. Because it makes no sense, since you want all objects and functions to share that variable, it's OK to define it as a static variable for the class.