Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 具有非类型模板参数成员函数的模板类_C++_Templates_Template Specialization - Fatal编程技术网

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
}