static volatile int k; 在。h 文件中这样写是错误的。
但是都在一个。cpp中是ok的
例如:
1 #include<iostream>
2
3 using namespace std;
4
5 int main()
6 {
7
8
9 static bool volatile s = false;
10 s= true;
11
12 while(s){
13
14 cout<<"========"<<endl;
15 return 0;
16 }
17
18
19 return 0;
20 }
这个程序是ok的。
原因是因为:因为你声明后就完成了定义啊,编译器不用决定s的值。
声明就完成了初始化,不需要编译器去决定初值
但是都在一个。cpp中是ok的
例如:
1 #include<iostream>
2
3 using namespace std;
4
5 int main()
6 {
7
8
9 static bool volatile s = false;
10 s= true;
11
12 while(s){
13
14 cout<<"========"<<endl;
15 return 0;
16 }
17
18
19 return 0;
20 }
这个程序是ok的。
原因是因为:因为你声明后就完成了定义啊,编译器不用决定s的值。
声明就完成了初始化,不需要编译器去决定初值