c++ - 具有非类型模板参数成员函数的模板类

标签 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();
};

//file.cc
void ClassA<int>::Execute<2>() { //Do stuff    }

我认为这更多是语法问题而不是设计问题,有什么线索吗?谢谢

最佳答案

即使你完全特化了一个模板,你仍然需要template<> :

template<> template<> void ClassA<int>::Execute<2>() { //Do stuff    }

关于c++ - 具有非类型模板参数成员函数的模板类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18384820/

相关文章:

c++ - 如何使用 std::ifstream 读取使用 QDataStream 编写的二进制文件

c++ - STL vector 数组

c++ - 插入数据时出现段错误

使用模板元编程的 C++ 生成函数

c++ - 在匿名命名空间中定义模板特化(和编译错误 C2888)

c++ - 将私有(private)内部类放入 main 中

c++ - 在赋值中折叠表达式

c++ - 为什么我们需要为每个类函数定义指定类型模板参数?

c++ - 我应该在哪里为我的 std::pair 特化定义运算符 >>?

C++ 专用函数模板