Because you don't have a default constructor the compiler complains that it can't create an object for primary
, you should either add a parameter to the secondary
constructor / give it a default value:
class secondary : public primary
{
public:
secondary(int x);
virtual ~secondary();
protected:
private:
};
And then call the base class constructor:
secondary::secondary(int x) : primary(x)
{
//ctor
}
Or:
secondary::secondary() : primary(5)
{
//ctor
}
Or just add a default constructor for primary
:
class primary
{
public:
primary(int x);
primary() : primary_x(0) {}
virtual ~primary();
protected:
private:
int primary_x;
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…