The differences between static and instance members of classes in C ++
In the C ++ class, static (static) data members and (static) function members belong to the class; on the contrary, members and functions that are not defined by static are called instance data members and instance function members. They belong to a certain instance (object ).
In the memory, static data members of a class occupy a specific memory space and are shared by all instances (objects) of the class. Instance data members of different objects of the same class are independent of each other and occupy their own storage space.
After defining a class, you must define static data members in the file scope outside the class to allocate storage space for them.
In a program, you can directly use the class name and domain resolution OPERATOR: directly contains a total of static data members and a total of function members of the class, rather than directly accessing private members of the class.
Static data members cannot be initialized in class constructors, because static data members do not belong to a specific class.
In a static function member of a class, only the static data member of the class can be called, but not the instance data member of the class, because when a static function member is called, you may not have created a specific instance (object) of the class ).