C++ classes support static member variables. When used, follow the principle of declaration within the class and definition outside the class. That is, the type and static attributes of the variable are declared inside the class, but the initial value cannot be assigned. Instead, it must be defined outside the class and assigned an initial value.
Such as class?class_type
{
static?var_type?var;?
};
var_type ?class_type::var?=?init_value;
In the initial value part, =init_value can be omitted. When omitted, the default value is 0.
In terms of use:
1 All member functions can use static variables;
2 If the static variable attribute is public, then any object a can be used Static variable var, the usage form is a.var;
3 If the static variable attribute is public, then you can use the following form to use the static variable var within the valid range of class class_type:
< p>class_type::var