这将编译与当前的MSVC编译器完美的罚款:未初始化的常量
struct Foo
{
} const foo;
但是,它未能与目前克至编译++编译器:
error: uninitialized const 'foo' [-fpermissive]
note: 'const struct Foo' has no user-provided default constructor
如果我提供一个默认的构造函数自己,它作品:
struct Foo
{
Foo() {}
} const foo;
这是MSVC的另一种情况是过于宽容,或者g ++太严格吗?
伟大的问题先生溢出。 –
Duplicates:http://stackoverflow.com/questions/5335836/why-a-const-object-of-an-empty-class-cant-be-created http://stackoverflow.com/questions/7411515/why- do-c-require-a-user-provided-default-constructor-to-default-construct-a等等。 – GManNickG
我无法在GCC 4.6.1上使用任何方言选项重现此操作。它只适用于我安装成员变量(如'int a;'),并且错误更加准确:''const struct Foo'没有用户提供的默认构造函数,隐式定义的构造函数不会初始化'int Foo :: a'' –