You may define a template member function outside of its class template definition.
template<class T> class X {
public:
T operator+(T);
};
template<class T> T X<T>::operator+(T arg1) {
return arg1;
};
int main() {
X<char> a;
X<int> b;
a +'z';
b + 4;
}
The overloaded addition operator has been defined outside
of class X. The statement a + 'z' is
equivalent to a.operator+('z'). The statement b
+ 4 is equivalent to b.operator+(4).