以下代码不能使用 gcc 编译:
struct test {
int x;
test() try : x{123} {
}
catch (...) {
}
};
int main() {}
错误:
prog.cpp:3:25: error: expected unqualified-id before ‘{’ token
test() try : x{123} {
^
prog.cpp:5:5: error: expected unqualified-id before ‘catch’
catch (...) {
^
prog.cpp: In constructor ‘test::test()’:
prog.cpp:3:23: error: expected ‘{’ at end of input
test() try : x{123} {
^
prog.cpp:3:23: error: expected ‘catch’ at end of input
prog.cpp:3:23: error: expected ‘(’ at end of input
prog.cpp:3:23: error: expected type-specifier at end of input
prog.cpp:3:23: error: expected ‘)’ at end of input
prog.cpp:3:23: error: expected ‘{’ at end of input
更改x{123}
为有x(123)
帮助。这应该(不)以这种方式工作吗?