C++ - 如何在模板化类之外实现模板化成员函数 [英] C++ - how to implement templated member function outside a templated class
本文介绍了C++ - 如何在模板化类之外实现模板化成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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!
是否有可能实现上述目标?我可以在类定义中实现 myFunction 没问题.如果是这样,语法是什么?GCC 4.2 告诉我:
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
感谢您的帮助
推荐答案
您正在寻找:
template <int N>
template <typename T>
void myClass<N>::myFunction() {}
类模板需要一个template
,成员函数模板需要一个.
You need one template
for the class template and one for the member function template.
这篇关于C++ - 如何在模板化类之外实现模板化成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文