0

I have code where I want to typedef a templated class for easier reading:

template<int A, int B>
using templateClass = templateClass<A,B>;

void aFunction(templateClass& tc);

int main(){
    templateClass<10, 34> tc;
    aFunction(tc);
}

void aFunction(templateClass& tc){
    ...
}

but I get many errors regarding the template identifiers not being found. How should this be done? I was trying to follow this example:

How to typedef a template class?

Community
  • 1
  • 1
user997112
  • 29,025
  • 43
  • 182
  • 361

2 Answers2

6

An alias template is useful when you only know some template parameters in advance:

template <class Value>
using lookup = std::map<std::string, Value>;

lookup<int> for_ints;
lookup<double> for_doubles;

It is unclear in your case whether you want a different name for a class template:

template <class A, class B>
class templateClass;

template <class A, class B>
using otherName = templateClass<A, B>;

if you already know the types you need:

typedef templateClass<int, double> int_double;

or if you just know one type:

template <class B>
using with_int = templateClass<int, B>;

In any case, you cannot have an alias with the same name as a class, like you're doing for templateClass.

isanae
  • 3,253
  • 1
  • 22
  • 47
5

templateClass is not a type; it's a type template. You still need to use the template keyword when defining templated functions with it.

template<int A, int B>
void aFunction(templateClass<A, B>& tc);
Pubby
  • 51,882
  • 13
  • 139
  • 180