简体   繁体   English

带有非类型模板的模板类参数成员函数

[英]template class with Non-type template Parameter member function

I am trying to define a specialization of a template class which contains a Non-type template Parameter member function. 我试图定义一个模板类的特化,其中包含一个非类型模板参数成员函数。 And I get the following error: 我收到以下错误:

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    }

I believe this is more of a syntax issue than a design issue, any clues? 我相信这更像是一个语法问题,而不是一个设计问题,任何线索? Thanks 谢谢

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

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

You forgot to tell the compiler that you're specializing a template method of a template class: 您忘了告诉编译器您正在专门化模板类的模板方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM