我有类基,它只包含私有默认构造函数和公共删除的复制构造函数,没有别的.
class base { private: base() = default; public: base(const base&) = delete; };
如果我尝试从base继承并创建一个派生类的实例,如下所示,g 4.8.2不会编译我的代码,但VC 2013会编译.
class derived : public base { private: derived() = default; }; derived x;
那么,它是g或VC 2013中的一个错误只是忽略了什么?
这是完整的代码……
class base { private: base() = default; public: base(const base&) = delete; }; class derived : public base { private: derived() = default; }; derived x; int main() { }
…和g错误消息.
main.cpp:12:5: error: 'constexpr derived::derived()' is private derived() = default; ^ main.cpp:15:9: error: within this context derived x; ^ main.cpp: In constructor 'constexpr derived::derived()': main.cpp:3:5: error: 'constexpr base::base()' is private base() = default; ^ main.cpp:12:5: error: within this context derived() = default; ^ main.cpp: At global scope: main.cpp:15:9: note: synthesized method 'constexpr derived::derived()' first required here derived x; ^