Martin wrote:
I'm trying to make a partial specialization of a class of mine.
No, you are not. You are confused.
Can
someone please tell me what's wrong with the following code? GCC gives
me the error "invalid use of undefined type "class X<int, B>"".
template <class A, class B>
class X
{
public:
void f();
};
template <>
void X<int, int>::f()
{ cout << "int-int";}
template <class B>
void X<int, B>::f() //error on this line
{ cout << "int-B"; }
The preceding definition (of 'X<int,B>::f') is NOT a partial specialisation
of the class template X. It's a definition of a member of the
*non-existent*
partial specialisation of 'X'. And that's prohibited. If you need to
define
a partial specialisation of 'X', do exactly that:
template<class B>
class X<int, B{
public:
void f();
};
and *only then* define the member.
>
int main( int argc, char** argv )
Don't declare arguments you're not going to use.
{
X<int, doublex;
x.f();
return 0;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask