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!
Run Code Online (Sandbox Code Playgroud)
嗨,
是否有可能实现上述目标?我可以在类定义中实现myFunction没问题.如果是这样,语法是什么?GCC 4.2告诉我:
缺少'>'来终止模板参数列表
谢谢你的帮助
Jam*_*lis 14
您正在寻找:
template <int N>
template <typename T>
void myClass<N>::myFunction() {}
Run Code Online (Sandbox Code Playgroud)
您需要一个template用于类模板,一个用于成员函数模板.
template<int N> template<typename T>
void myClass<N>::myFunction() {}
Run Code Online (Sandbox Code Playgroud)