我试图创建一个子类secondary
,它可以与参数一起使用以及重写类primary
。现在,我得到初始化派生类的构造函数中没有默认构造函数的基类
没有匹配函数来调用
错误。有人能帮助我吗?
我的代码:
primary.h:
#ifndef PRIMARY_H
#define PRIMARY_H
class primary
{
public:
primary(int x);
virtual ~primary();
protected:
private:
int primary_x;
};
#endif // PRIMARY_H
primary.cpp:
#include "primary.h"
primary::primary(int x)
{
primary_x = x;
}
primary::~primary()
{
//dtor
}
secondary.h:
#ifndef SECONDARY_H
#define SECONDARY_H
#include "primary.h"
class secondary : public primary
{
public:
secondary();
virtual ~secondary();
protected:
private:
};
#endif // SECONDARY_H
secondary.cpp:
#include "secondary.h"
secondary::secondary()
{
//ctor
}
secondary::~secondary()
{
//dtor
}
的[类可能的复制从类继承,但没有默认构造函数](http://stackoverflow.com/questions/3714162/class-inherited-from-class-without-default-constructor) –