静态变量加前缀 s_(表示 static)

静态变量加前缀 s_(表示 static)。 例如: void Init(…) { static int s_initValue; // 静态变量 … }

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 //用struct关键字定义ex_class类
 6 struct ex_class {
 7     ex_class(int n=1): value(n) {}
 8     void set_value(int n) {
 9          value=n;
10     }
11     show_obj(char *name) {
12         cout<<name<<": "<<value<<endl;
13     }
14 private:
15     int value;
16 };
17 int main(int argc, char** argv) {
18         //用ex_class创建对象
19     ex_class a,b(3);
20     
21     a.show_obj("a");
22     b.show_obj("b");
23 
24     a.set_value(100);
25     b.set_value(200);
26 
27     a.show_obj("a");
28     b.show_obj("b");
29     return 0;
30 }
原文地址:https://www.cnblogs.com/borter/p/9413434.html