-1

What am I doing wrong?

#include "String.hpp"

namespace java {
      namespace lang {


template<typename  T>
class Comparable<T>  {

protected:
     virtual int8_t compareTo(T& o);
};

}


}



#endif // COMPARABLE_H

I haven't declared this class anywhere before

Comparable.h:11:7: error: explicit specialization of undeclared template class 'Comparable'
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Amos
  • 123
  • 1
  • 4

1 Answers1

2

When defining a template class you don't need the template argument in the class name:

template<typename  T>
class Comparable<T>  { /* ... */ };
//              ^^^
//     Invalid here

Just remove that part:

template<typename  T>
class Comparable  { /* ... */ };
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Now i have LINK error. when i extended this class – Amos Apr 11 '21 at 06:20
  • @Amos Possibly because of [this problem](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file). Or possibly because non-abstract virtual functions *must* have a definition (implementation). – Some programmer dude Apr 11 '21 at 06:21
  • i implement this virtual function, but because of the template it is not build, probably – Amos Apr 11 '21 at 06:24
  • @Amos Then please follow the link in my comment to see the most likely problem and how to solve it. – Some programmer dude Apr 11 '21 at 06:32
  • I managed to build with template, using a dummy implementation of a virtual function – Amos Apr 11 '21 at 06:46