C++11 in-class initializer with MSVC 2013
以下代码与mingw-gcc-4.8.2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // test.cpp #include <iostream> class Test { public: int a[10] = {}; }; int main() { Test c; std::cout << c.a[0]; return 0; } |
但是,当我在
1 2 3 4 5 6 | test.cpp test.cpp(6) : fatal error C1001: 编译器中发生内部错误。 (编译器文件"f:\dd\vctools\compiler\cxxfe\sl\p1\c\convert.cpp",第 9608 行) 要解决此问题,请尝试简化或更改上面所列位置附近的程序。 请选择 Visual C++ "帮助"菜单上的"技术支持"命令,或打开技术支持帮助文件来获得详细信息。 |
正如微软开发人员网络上所说,这条消息是由于编译/构建优化而产生的,因此您可以尝试删除此优化。
The compiler cannot generate correct code for a construct, probably due to the combination of an expression and an optimization option. Try removing one or more optimization options and recompiling the function containing the line indicated in the error message.
You can probably fix the problem by removing one or more optimization options. To determine which option is at fault, remove options one at a time and recompile until the error message goes away. The options most commonly responsible are /Og, /Oi, and /Oa. Once you determine which option is responsible, you can disable it using the optimize pragma around the function where the error occurs and continue to use the option for the rest of the module.
正如他们在这里所说,您可以使用