I came up with the following pattern and wondered if there was a name for it?
An enumdefines specific classes:
enum Fruits{ eApple, eBanana };
And the template structprovides an interface:
template< Fruit T >
struct SomeFruit {
void eatIt() {
};
Then we can implement specific classes:
template<>
struct SomeFruit< eApple > {
void eatIt() {
};
template<>
struct SomeFruit< eBanana > {
void eatIt() {
};
And use them this way:
SomeFruit< eApple> apple;
apple.eatIt();
source
share