此代码无法使用 gcc 4.7.0 编译:
class Base
{
public:
Base(const Base&) = delete;
};
class Derived : Base
{
public:
Derived(int i) : m_i(i) {}
int m_i;
};
错误是:
c.cpp: In constructor `Derived::Derived(int)´:
c.cpp:10:24: error: no matching function for call to `Base::Base()´
c.cpp:10:24: note: candidate is:
c.cpp:4:2: note: Base::Base(const Base&) <deleted>
c.cpp:4:2: note: candidate expects 1 argument, 0 provided
换句话说,编译器不会为基类生成默认构造函数,而是尝试调用已删除的复制构造函数作为唯一可用的重载。
这是正常的行为吗?