I have happened upon the following pattern, and wondered if there is a name for it?
An enum
defines the concrete classes:
enum Fruits{ eApple, eBanana };
And a templated struct
provides the interface:
template< Fruit T >
struct SomeFruit {
void eatIt() { // assert failure };
};
We can then implement the concrete classes thus:
template<>
struct SomeFruit< eApple > {
void eatIt() { // eat an apple };
};
template<>
struct SomeFruit< eBanana > {
void eatIt() { // eat a banana };
};
And use them thus:
SomeFruit< eApple> apple;
apple.eatIt();