S
Simon G Best
Hello!
I'm trying to specialize a member function template of a class template,
like this:-
template<typename T> class thingy {
public:
template<typename U> T f (const U &) const;
};
// The general case:-
template<typename T> template<typename U> T thingy<T>::f
(const U &x) const {
return T(x);
}
// The special case:-
template<typename T> template<> T thingy<T>::f<T>
(const T &x) const {
return x;
}
But it's not working :-( I've tried a few variations (such as throwing
in a 'template' to disambiguate), but my compilers (G++ 4.1.2 and G++
3.3.6) just don't seem to like it. With the above C++, I'm getting the
following out of G++ 4.1.2:-
templates.cpp:13: error: invalid explicit specialization before ‘>’ token
templates.cpp:13: error: enclosing class templates are not explicitly
specialized
templates.cpp:14: error: template-id ‘f<T>’ for ‘T thingy<T>::f(const
T&) const’ does not match any template declaration
templates.cpp:14: error: invalid function declaration
:-(
What am I doing wrong?
Simon
I'm trying to specialize a member function template of a class template,
like this:-
template<typename T> class thingy {
public:
template<typename U> T f (const U &) const;
};
// The general case:-
template<typename T> template<typename U> T thingy<T>::f
(const U &x) const {
return T(x);
}
// The special case:-
template<typename T> template<> T thingy<T>::f<T>
(const T &x) const {
return x;
}
But it's not working :-( I've tried a few variations (such as throwing
in a 'template' to disambiguate), but my compilers (G++ 4.1.2 and G++
3.3.6) just don't seem to like it. With the above C++, I'm getting the
following out of G++ 4.1.2:-
templates.cpp:13: error: invalid explicit specialization before ‘>’ token
templates.cpp:13: error: enclosing class templates are not explicitly
specialized
templates.cpp:14: error: template-id ‘f<T>’ for ‘T thingy<T>::f(const
T&) const’ does not match any template declaration
templates.cpp:14: error: invalid function declaration
:-(
What am I doing wrong?
Simon