I want to templatize the casting operator with a specialization for bool, but it's not working.
template<typename T> //Don't know if the fact that C is templated itself is relevant here
class C
{
...
template<typename U> operator U() const { return another_namespace::MyCast<U>(*this); }
template<> operator bool() const { return IsValid(); }
};
This gives me (g++ 4.6)
explicit specialization in non-namespace scope ‘class C< T>’
Now just
operator bool() const { return IsValid(); }
by itself works, as does MyCast (it's a friend function declared in an external namespace). Is there any way I can get the intended behHoavior here?
Edit: I have subsequently found this, looks like the same basic question, however the answer (which gives a very complicated solution) looks designed specifically for strings. Also, the issue there turned out to be ambiguity, which I think is not the problem here--I get a very different compiler error message.