Suppose I write a class as follows:
Code:
template <class T1>
class have_a_try
{
public:
template <class T2>
T2 test( const T2&, const T2& );
private:
T1 se;
};
template<class T1>
template<class T2>
T2 have_a_try<T1>::test( const T2& a, const T2& b )
{
return a;
}
As you could see, test is a template member. Now, I'd like to make a special version of test to handle arguments of type int (test<int>) no matter how the template class have_a_try is instantiated, that's, no matter have_a_try is instantiated for type int, double, string... if the actual arguments passed to that instance is of type int, the specialized version of test is called. I've tried the following code but failed.
Code:
template<class T1>
template<>
int have_a_try<T1>::test<int>( const int& a, const int& b )
{
return a;
}
One of my friend asked me this question just now but I still cannot solve it. I guess it's impossible to make a specialized version of a member template while leaving the class template generic.
Dear all, please help me.