Pre {Line-Height: 1; color: # 1e1e1e; Background-color: # f0f0f0; font-size: 16px ;}. sysfunc {color: #627cf6; font-style: italic; font-weight: bold ;}. selffuc {color: #800080 ;}. bool {color: # d2576f ;}. condition {color: #000080; font-weight: bold ;}. key {color: #000080 ;}. vaR {color: #800000; font-style: italic ;}. digit {color: # ff00ff; font-weight: bold ;}. includepre {color: # 1e1e1e ;}. operator? {Color: #008000; font-weight: bold ;}
Static member variable
1. static member functions can only access static variables because static variables do not include the this pointer.
2 static member variables ?? It is not only shared by all objects of the class, but also shared by objects of the derived class.
Example:
?class?base{public:?????????static?int?num;};?int?base::num=0;?class?derived:public?base{};??????????base?a;?????????derived?b;?????????a.num++;?????????cout<<a.num<<endl;??????????b.num++;?????????cout<<b.num<<endl;?
3? A static member of a class can be an optional parameter of a member function, but a common member cannot.
Example:
Class? Base {? Public :????????? Static? Int? Num ;?????????? Int? VaR ;?????????? Void? F1 (Int? I = num );?? //? Correct ????????? Void? F2 (Int? I = var );?? //? Error };?
4? A static member of a class can be of the class type, but a common member cannot. A common member can only be declared as a pointer or reference of the class type.
? Class? Base {? Public :????????? Static? Base? Num ;?????????? Base? VaR ;? //? Error ?????????? Base? * Pbase ;?????????? Base? & Mybase ;};
Used in this article? Calligraphy and painting novel software? Released, the content has nothing to do with the software, and the painting and calligraphy novel software? More comfortable reading, more comfortable writing, and easier Publishing.
Static member variable. xml