tmpl.h
#include <iostream.h>
template <int n>
class myClass
{
public:
void myFunc ();
void inFunc();
};
tmpl.cxx
#include "tmpl.h"
template<>
void myClass<2>::inFunc ()
{
myFunc();
}
template <>
void myClass<2>::myFunc () const
{
std::cout << "Two is very special!\n";
}
int main( int argc, char** argv )
{
myClass<2> c2;
c2.inFunc();
return 0;
}
template class myClass<1>;
template class myClass<2>;
g++ tmpl.cxx
tmpl.cxx:19: error: specialization of void myClass<n>::myFunc() [with int n = 2] after instantiation tmpl.cxx:19: error: prototype for `void myClass<n>::myFunc() [with int n = 2]' does not match any in class `myClass<2>' tmpl.h:6: error: candidate is: void myClass<n>::myFunc() [with int n = 2] tmpl.cxx:19: error: `void myClass<n>::myFunc() [with int n = 2]' and `void myClass<n>::myFunc() [with int n = 2]' cannot be overloaded
I am not able to understand why this is happening. Anybody any insight?
Please note that the above code is a simplification of my actual code. So, don't suggest to specialize the whole class. The actual class contains other member functions which are not to be specialized.











