1

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:

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. Does someone has a clue why I get this error?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
spreisel
  • 391
  • 1
  • 3
  • 7

1 Answers1

1

Jobmaster is a class template. So you need to provide the template arguments in the JobCalcReturn constructor's definition:

JobCalcReturn::JobCalcReturn(const std::string& _JSONin) 
: JobMaster<DataInClass, Poco::JSON::Array>(_JSONin){}

Also note that _JSONin is a reserved identifier. You need to use a different name.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • Thanks @juanchopanza for the hint with the reserved identifier, but i tryed this and get a new error in the header file: `error: expected template-name before ‘<’ token error: expected ‘{’ before ‘<’ token error: expected unqualified-id before ‘<’ token` in this line: `class JobCalcReturn :public JobMaster` Isn't JobMaster my template-name? – spreisel Feb 07 '15 at 15:43