回复 2楼 rjsp
您好,那您的意思是人家代码是正确的,我的编译器比较老吗?
我用的是visual studio 2019,编译器应该是其自带的,我查看了有个MSVC 14.2的。
我刚才网页上点击运行您写的代码,也有如下提示和错误
程序代码:
6:20: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
int value{ 123 };
^
6:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
int value{ 123 };
^
6:20: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
int value{ 123 };
^
In function ‘int main()’:
11:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
foo a {};
^
11:12: error: in C++98 ‘a’ must be initialized by constructor, not by ‘{...}’
foo a {};
^
12:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
foo b { 1, 2 };
^
12:18: error: in C++98 ‘b’ must be initialized by constructor, not by ‘{...}’
foo b { 1, 2 };
^
13:14: error: in C++98 ‘c’ must be initialized by constructor, not by ‘{...}’
foo c = {};
^
14:20: error: in C++98 ‘d’ must be initialized by constructor, not by ‘{...}’
foo d = { 1, 2 };