When I compile the following
#include <iostream>
#define XXX 1
#define YYY 2
class X
{
public:
template< int FLD >
void func();
};
template<> void X::func< XXX >()
{
std::cout << "X::func< " << XXX << " >" << std::endl;
}
class Y : public X
{
public:
};
template<> void Y::func< YYY >()
{
std::cout << "Y::func< " << YYY << " >" << std::endl;
}
template<> void Y::func< XXX >()
{
std::cout << "Y::func< " << XXX << " >" << std::endl;
}
int main( int c, char *v[] )
{
X x;
Y y;
}
I get
x.cpp:24: error: template-id 'func<2>' for 'void Y::func()' does not match any template declaration
x.cpp:24: error: invalid function declaration
x.cpp:29: error: template-id 'func<1>' for 'void Y::func()' does not match any template declaration
x.cpp:29: error: invalid function declaration
I'm trying to specialise a template in a base class.
Can anyone explain either how it's done or why I can't do it.
Thx Mark.