Ricardo_arg
Ricardo_arg

Reputation: 520

non template class using a template class as member variable

hi i am stuck tryng to use a class declaring as template class, thus my knowledge of templates is basic.

//this is my code
#include "templateClassImp.cpp"
clase aClass{
public:
aClass();//implementing in cpp file
private:
ATemplateClass<class EMode, char> mMenberVariable;/*<< Doenst like this!!!! error compiling*/
}

//--------------------------

//templateClassImp.cpp

template<class Emode, class element = char>
class templateClassImp{}

//what i want to achieve is to use that class inside my non template class.

Upvotes: 0

Views: 2141

Answers (2)

juanchopanza
juanchopanza

Reputation: 227370

You have to either make aClass a class template, or provide template parameters for mMenberVariable.

template <class T1, class T2=char>
class aClass
{
public:
  aClass();
private:
  ATemplateClass<T1, T2> mMenberVariable;
};

or

class aClass
{
public:
  aClass();
private:
  ATemplateClass<int, double> mMenberVariable;
};

Upvotes: 6

Dory Zidon
Dory Zidon

Reputation: 10719

you have to parameterize all template parameters in a template definition to use it.

ATemplateClass<EMode, char> mMenberVariable

Upvotes: -1

Related Questions