[英]c++ error inheriting baseClass with template
I've a question about an error I get by inherenting a template base class. 我对固有于模板基类的错误有疑问。 I get this error in my subclass source file:
我的子类源文件中出现此错误:
error: class ‘JobCalcReturn’ does not have any field named ‘JobMaster’
my base class as a *.h file: 我的基类为* .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
};
my subclass header: 我的子类头:
class DataInClass{...};
class JobCalcReturn :public JobMaster<DataInClass, Poco::JSON::Array>
{
public:
JobCalcReturn(const std::string &_JSONin);
~JobCalcReturn();
private:
std::string dataInHandler(DataInClass& calcRatrunData);
};
my subclass source file: 我的子类源文件:
JobCalcReturn::JobCalcReturn(const std::string& _JSONin) : JobMaster(_JSONin){}
//here in the constructor i get the error
JobCalcReturn::~JobCalcReturn(){}
std::string JobCalcReturn::dataInHandler(DataInClass& calcRatrunData){...}
I wrote this with Visual Studio 2013 and got no error, then I switch the system to Linux with eclipse and the gcc c++ compieler and I get this error. 我是用Visual Studio 2013编写的,没有任何错误,然后我使用eclipse和gcc c ++ compieler将系统切换到Linux,但出现此错误。 Does someone has a clue why I get this error?
有人知道为什么我会收到此错误吗?
Jobmaster
is a class template. Jobmaster
是一个类模板。 So you need to provide the template arguments in the JobCalcReturn
constructor's definition: 因此,您需要在
JobCalcReturn
构造函数的定义中提供模板参数:
JobCalcReturn::JobCalcReturn(const std::string& _JSONin)
: JobMaster<DataInClass, Poco::JSON::Array>(_JSONin){}
Also note that _JSONin
is a reserved identifier . 另请注意,
_JSONin
是保留标识符 。 You need to use a different name. 您需要使用其他名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.