开发者

C++ - how to implement templated member function outside a templated class

开发者 https://www.devze.com 2023-02-07 03:15 出处:网络
template<int N> class myClass { template<typename T> void myFunction(); }; template<typename T>
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 poss开发者_开发百科ible 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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消