Q
quarup
I want to specialize a template function that lives inside a class, but
am getting a compile error in VS.net 2003. Here's my code:
template <class T>
class A {
public:
template <class U>
void f() const;
};
template <class T>
template <>
void A<T>::f<int>() const {}
I get the following errors:
c:\programming\testCPP\testCPP.cpp(19) : error C2768: 'A<T>::f' :
illegal use of explicit template arguments
c:\programming\testCPP\testCPP.cpp(19) : error C2768: 'A<T>::f' :
illegal use of explicit template arguments
c:\programming\testCPP\testCPP.cpp(19) : error C2244: 'f' : unable to
match function definition to an existing declaration
definition
'void A<T>::f<int>(void) const'
existing declarations
'void A<T>::f(void) const'
For comparison, here are two situations that DO work:
1. non-specialized template function inside template class works:
template <class T>
class B {
public:
template <class U>
void f() const;
};
template <class T>
template <class U>
void B<T>::f() const {}
2. specialized template function inside non-template class works:
class C {
public:
template <class U>
void f() const;
};
template <>
void C::f<int>() const {}
Does anyone have any insights? Am I not confirming to the standard, is
my syntax incorrect, or is VS.net broken?
am getting a compile error in VS.net 2003. Here's my code:
template <class T>
class A {
public:
template <class U>
void f() const;
};
template <class T>
template <>
void A<T>::f<int>() const {}
I get the following errors:
c:\programming\testCPP\testCPP.cpp(19) : error C2768: 'A<T>::f' :
illegal use of explicit template arguments
c:\programming\testCPP\testCPP.cpp(19) : error C2768: 'A<T>::f' :
illegal use of explicit template arguments
c:\programming\testCPP\testCPP.cpp(19) : error C2244: 'f' : unable to
match function definition to an existing declaration
definition
'void A<T>::f<int>(void) const'
existing declarations
'void A<T>::f(void) const'
For comparison, here are two situations that DO work:
1. non-specialized template function inside template class works:
template <class T>
class B {
public:
template <class U>
void f() const;
};
template <class T>
template <class U>
void B<T>::f() const {}
2. specialized template function inside non-template class works:
class C {
public:
template <class U>
void f() const;
};
template <>
void C::f<int>() const {}
Does anyone have any insights? Am I not confirming to the standard, is
my syntax incorrect, or is VS.net broken?