So I have a templated Image class, for which I am trying to set up inline color-conversions. This is a simplification of the code that is vexing me:
template <typename Color = colors::RGB>
class Image {
/// ...
template <typename DestColor>
operator Image<DestColor>() {
/// when assigning with a different colorspace:
/// ... do the color conversion
/// ... and return a fresh Image<DestColor>
}
template <>
operator Image<Color>() {
/// when assigning with the same colorspace:
return *this;
}
};
… the problem is that the template specialization that follows the templated conversion operator can’t be defined at the class level (according to the errors I am getting).
I get that one needs to specify the specialization out-of-line, but I can’t for the life of me figure out the syntax. How should I declare that specialization?