我有代码:
struct A {
int a;
};
struct B {
int b;
const A a[2];
};
struct C {
int c;
const B b[2];
};
const C test = {0, {}};
int main()
{
return test.c;
}
我有 gcc 4.8.2 和 4.9.2。它可以编译得很好:
g++-4.9 -Wall test.cpp -o test
g++-4.8 -std=c++11 -Wall test.cpp -o test
g++-4.8 -Wall test.cpp -o test
但是,它不能编译为:
g++-4.9 -std=c++11 -Wall test.cpp -o test
编译器输出是:
test.cpp:15:22: error: uninitialized const member ‘B::a’
const C test = {0, {}};
^
test.cpp:15:22: error: uninitialized const member ‘B::a’
这是一个错误还是我只是不明白什么?