2

Suppose I have the following class:

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

  template<bool U>
  bool something(); // line 10
};

I want to specialize the method Dummy<T>::something. I've tried:

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

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

But I receive these errors:

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();

Is this occurring because it is a form of partial specialization (which I know is not allowed in C++11) or for some other reason? Note that I in no way intend to use the code described above. It is simply to demonstrate something similar which exists in my original code.

Alex Brooks
  • 1,151
  • 1
  • 10
  • 39
  • 1
    As usual, clang++'s error message is easier to understand: "cannot specialize a member of an unspecialized template" – dyp Feb 06 '15 at 22:40
  • possible duplicate of [Specialization of templated member function in templated class](http://stackoverflow.com/questions/6773302/specialization-of-templated-member-function-in-templated-class) – Alex Brooks Feb 06 '15 at 22:46
  • 1
    Thanks, I found a duplicate to my question, which the answer can hopefully serve as a solution in my case. – Alex Brooks Feb 06 '15 at 22:46

0 Answers0