1. Static members
(1) modified by the keyword static
The static variable definition statement is executed at the compilation stage and no longer executed during the running process.
(2) classification: static data members and static member functions.
(3) When a static member is used, all objects of the class share members, rather than members of an object.
2. Use of static members
(1) Add the static keyword before the definition description. For example:
Static int x;
(2) static data members must be initialized and the initialization must be completed outside the class.
(3) static data member Initialization
Data Type Class Name: static data member name = value; // note that no static data appears here
(4) object names cannot be used to use static data members. Again, it is emphasized that static data members belong to the whole class of public, rather than an object.
Object Name. static member name // Error
(5) correct usage
Class Name: static data member
(6) If the access permissions of static data members are permitted, they can be accessed outside the class.
3. Example of static data members
# Include
Class Tc
{
Int I;
Static int k;
Public:
Tc ()
{
I = 0;
I ++;
K ++;
}
Void display ()
{
Cout <"I =" <