C++ 具有非类型模板参数成员函数的模板类
我试图定义一个包含非类型模板参数成员函数的模板类的专门化。我得到以下错误:C++ 具有非类型模板参数成员函数的模板类,c++,templates,template-specialization,C++,Templates,Template Specialization,我试图定义一个包含非类型模板参数成员函数的模板类的专门化。我得到以下错误: error: too few template-parameter-lists Here's a sample class that describes the problem in brief, // file.h template <typename T> class ClassA { T Setup(); template <int K> static void Execute()
error: too few template-parameter-lists
Here's a sample class that describes the problem in brief,
// file.h
template <typename T>
class ClassA {
T Setup();
template <int K> static void Execute();
};
//file.cc
void ClassA<int>::Execute<2>() { //Do stuff }
错误:模板参数列表太少
下面是一个简单描述问题的示例类,
//文件.h
模板
甲级{
T设置();
模板静态void Execute();
};
//file.cc
void ClassA::Execute(){//Do stuff}
我相信这更多的是一个语法问题而不是设计问题,有什么线索吗?谢谢即使您完全专业化了一个模板,您仍然需要
模板
:
模板模板void ClassA::Execute(){//Do stuff}
您忘记告诉编译器您正在专门化模板类的模板方法:
template <>
template <>
void ClassA<int>::Execute<2>()
{
//Do stuff
}
模板
模板
void ClassA::Execute()
{
//做事
}
这会引发错误:“void ClassA::Execute()”的模板id“Execute”与任何模板声明都不匹配,这是因为它需要像我的回答中指出的那样说两次template
(一次用于类,一次用于函数)。哎哟,错过了函数模板。谢谢,@MarkByep,需要添加两次,很有趣。谢天谢地
template <>
template <>
void ClassA<int>::Execute<2>()
{
//Do stuff
}