- c++98允许在类中使用“=”对静态常成员变量初始化
- c++11支持在类中对非静态成员变量进行初始化,但支持“=”,也支持“{}”,不支持"()"
- 两者都不支持对静态非常成员变量的初始化
9 #include <iostream>
10 #include <string>
11
12 class Init
13 {
14 public:
15 void print()
16 {
17 std::cout<<a<<b<<c<<d<<e<<std::endl;
18 }
19 private:
20 int a = 0; //c++11标准支持
21 const int b = 1; ///c++11标准支持
22 const static int e = 4; //c++98支持
23 static int c = 2; //两者都不支持
24 static const int d = 3; //gnu对c++的扩展,不是c++标准
25 std::string str= "ddfd"; //c++11标准支持
std::string str1{"ddfd"}; //c++11标准支持
std::string str2("ddfd"); //c++11标准不支持
26 };
27
28 int main()
29 {
30 Init init;
31 init.print();
32 return 0;
33 }