3

我正在尝试定义包含非类型模板参数成员函数的模板类的专业化。我收到以下错误:

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    }

我相信这更像是一个语法问题而不是设计问题,有什么线索吗?谢谢

4

2 回答 2

5

即使您完全专业化模板,您仍然需要template<>

template<> template<> void ClassA<int>::Execute<2>() { //Do stuff    }
于 2013-08-22T15:32:01.513 回答
4

您忘记告诉编译器您正在专门化模板类的模板方法:

template <>
template <>
void ClassA<int>::Execute<2>()
{
    //Do stuff
}
于 2013-08-22T15:33:22.283 回答