Hello,
I want to write specialized method for a class:
template<class A, class B>
class xxx{
A a; B b;
operator bool()const{
a==b;
}
};
What I want to do is to be able to specialize operator bool for the
case when class A=std::string, so that in that case it returned
a.length()>0;
For this to work I have a choice to copy my class xxx definition like
this:
template<class B>
class xxx<std::string, B>{
std::string a; B b;
operator bool()const{
a.length()>0;
}
};
But I have a large class where I need to specialize several methods.
What I want to do is to specialize only the method operator bool:
template<class A, class B>
class xxx{
A a; B b;
operator bool()const;
};
//default implementation
template<class A, class B>
xxx<A,B>::operator bool()const{
return a==b;
}
//specialized method, doesn't compile
template<class B>
xxx<std::string, B>::operator bool()const{
return a.length()>0;
}
but it doesn't work like this. What's the mistake, how to do it the
right way?
I use vs2003
Thank you.