I would like to know if I can specialize only a specific method for a
class template.
Is the (specialization ) code below valid?
template <typename T1, typename T2>
class MyClass
{
public:
MyClass(const T1&);
~MyClass();
//Not implemented inline
MyClass * instance(const string& arg1);
T1 foo1(T1){ //implementation here ; }
T2 foo2(T2){ //implementation here ; }
T1 foobar1(T1,T2){ //implementation here ; }
T2 foobar2(T2,T1){ //implementation here ; }
}
//Specialization of only the instance() method
template <>
MyClass<int, string* MyClass<int, string>::instan ce(const string& arg1)
{
}
template <>
MyClass<double, double* MyClass<double, double>::instan ce(const
string& arg1)
{
}
class template.
Is the (specialization ) code below valid?
template <typename T1, typename T2>
class MyClass
{
public:
MyClass(const T1&);
~MyClass();
//Not implemented inline
MyClass * instance(const string& arg1);
T1 foo1(T1){ //implementation here ; }
T2 foo2(T2){ //implementation here ; }
T1 foobar1(T1,T2){ //implementation here ; }
T2 foobar2(T2,T1){ //implementation here ; }
}
//Specialization of only the instance() method
template <>
MyClass<int, string* MyClass<int, string>::instan ce(const string& arg1)
{
}
template <>
MyClass<double, double* MyClass<double, double>::instan ce(const
string& arg1)
{
}
Comment