请看下面的例子:
class Base
{
protected:
int m_nValue;
public:
Base(int nValue)
: m_nValue(nValue)
{
}
const char* GetName() { return "Base"; }
int GetValue() { return m_nValue; }
};
class Derived: public Base
{
public:
Derived(int nValue)
: Base(nValue)
{
}
Derived( const Base &d ){
std::cout << "copy constructor\n";
}
const char* GetName() { return "Derived"; }
int GetValueDoubled() { return m_nValue * 2; }
};
Run Code Online (Sandbox Code Playgroud)
这段代码不断给我一个错误,即基类没有默认的构造函数.当我宣布一切都好的时候.但是当我不这样做时,代码不起作用.
如何在派生类中声明复制构造函数而不在基类中声明默认的构造函数?
Thnaks.