我試圖創建一個子類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) –