我有一个关于我通过一个模板基类来实现的错误的问题。我在子类源文件中收到此错误:
error: class ‘JobCalcReturn’ does not have any field named ‘JobMaster’
我的基类为* .h文件:
template<class dataIn, class dataOut>
class JobMaster
{
public:
JobMaster() : JSONin("NOP"){};
JobMaster(const std::string &_JSONin) : JSONin(_JSONin){};
virtual ~JobMaster(){};
private:
static dataIn dataInObject;
static dataOut dataOutObject;
const std::string &JSONin;
static std::string JSONout;
virtual std::string dataInHandler(dataIn& dataInObject){...};
//Some more virutal methodes
};
我的子类标题:
class DataInClass{...};
class JobCalcReturn :public JobMaster<DataInClass, Poco::JSON::Array>
{
public:
JobCalcReturn(const std::string &_JSONin);
~JobCalcReturn();
private:
std::string dataInHandler(DataInClass& calcRatrunData);
};
我的子类源文件:
JobCalcReturn::JobCalcReturn(const std::string& _JSONin) : JobMaster(_JSONin){}
//here in the constructor i get the error
JobCalcReturn::~JobCalcReturn(){}
std::string JobCalcReturn::dataInHandler(DataInClass& calcRatrunData){...}
我用Visual Studio 2013编写了这个并且没有错误,然后我用eclipse和gcc c ++ compieler将系统切换到Linux,我得到了这个错误。有人知道为什么我会收到这个错误吗?
答案 0 :(得分:1)
Jobmaster
是一个类模板。因此,您需要在JobCalcReturn
构造函数的定义中提供模板参数:
JobCalcReturn::JobCalcReturn(const std::string& _JSONin)
: JobMaster<DataInClass, Poco::JSON::Array>(_JSONin){}
另请注意,_JSONin
是reserved identifier。您需要使用其他名称。