Templates 模板类中模板方法的特殊化

Templates 模板类中模板方法的特殊化,templates,c++11,template-specialization,Templates,C++11,Template Specialization,假设我有以下课程: template<typename T> class Dummy { public: Dummy() {} template<bool U> bool something(); // line 10 }; 模板 类虚拟{ 公众: Dummy(){} 模板 bool something();//第10行 }; 我想专门化方法Dummy::something。我试过: template<typename T> bool Du

假设我有以下课程:

template<typename T>
class Dummy {
 public:
  Dummy() {}

  template<bool U>
  bool something(); // line 10
};
模板
类虚拟{
公众:
Dummy(){}
模板
bool something();//第10行
};
我想专门化方法
Dummy::something
。我试过:

template<typename T>
bool Dummy<T>::something<true>() { // line 14
  return true;
}

template<typename T>
bool Dummy<T>::something<false>() { // line 19
  return false;
}
模板
bool Dummy::something(){//第14行
返回true;
}
模板
bool Dummy::something(){//第19行
返回false;
}
但我收到了以下错误:

test.h:14:32: error: template-id ‘something<true>’ in declaration of primary template
 bool Dummy<T>::something<true>() {
                                ^
test.h:14:6: error: prototype for ‘bool Dummy<T>::something()’ does not match any in class ‘Dummy<T>’
 bool Dummy<T>::something<true>() {
      ^
test.h:10:8: error: candidate is: template<class T> template<bool b> bool Dummy<T>::something()
   bool something();
        ^
test.h:19:33: error: template-id ‘something<false>’ in declaration of primary template
 bool Dummy<T>::something<false>() {
                                 ^
test.h:19:6: error: prototype for ‘bool Dummy<T>::something()’ does not match any in class ‘Dummy<T>’
 bool Dummy<T>::something<false>() {
      ^
test.h:10:8: error: candidate is: template<class T> template<bool b> bool Dummy<T>::something()
   bool something();
test.h:14:32:错误:主模板声明中的模板id为'something'
bool Dummy::something(){
^
test.h:14:6:错误:“bool Dummy::something()”的原型与类“Dummy”中的任何原型都不匹配
bool Dummy::something(){
^
test.h:10:8:错误:候选项是:模板bool Dummy::something()
bool某物();
^
test.h:19:33:错误:主模板声明中的模板id“something”
bool Dummy::something(){
^
test.h:19:6:错误:“bool Dummy::something()”的原型与类“Dummy”中的任何原型都不匹配
bool Dummy::something(){
^
test.h:10:8:错误:候选项是:模板bool Dummy::something()
bool某物();

发生这种情况是因为它是部分专门化的一种形式(我知道在C++11中是不允许的)还是其他原因?请注意,我根本不打算使用上述代码。这只是为了演示我的原始代码中存在的类似内容。

与往常一样,clang++的错误消息更容易理解:“不能专门化一个非专业化模板的成员”可能的重复感谢,我发现了我的问题的一个重复,这个答案有望作为我的问题的解决方案。