我可以在类主体中默认一个私有构造函数吗?



GCC 4.5不允许我这样做:

class foo {
public:
    foo() = default;
private:
    foo(foo const&) = default;
    foo& operator=(foo const&) = default;
};

它抱怨:

error: 'foo::foo(const foo&)'声明的非公共访问不能在类体中默认
错误:"foo&用非公共访问声明的Foo::operator=(const Foo &)'不能在类体中默认

然而,GCC 4.6允许我这样做。哪一个是正确的?

N3291中没有规定不能声明某物privatedefault。请注意,这是对第8.4.2节第2段中规范的更改;较早的版本要求它们必须是公开的

相关内容

最新更新