14
template<int N>
class myClass
{
    template<typename T>
    void myFunction();
};

template<typename T>
void myClass<int N>::myFunction() {} // doesn't work, nor do many other combinations!

Hi,

Is it possible to achieve the above? I can implement myFunction in the class definition no problem. If so what would the syntax be? GCC 4.2 tells me:

missing '>' to terminate the template argument list

thanks for your help

Oli Larkin
  • 141
  • 1
  • 3

2 Answers2

18

You are looking for:

template <int N>
template <typename T> 
void myClass<N>::myFunction() {} 

You need one template for the class template and one for the member function template.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
4
template<int N> template<typename T>
void myClass<N>::myFunction() {}
aschepler
  • 70,891
  • 9
  • 107
  • 161