You are viewing a single comment's thread. Return to all comments →
template <typename T> struct Traits; template <typename T> union Frulor { int index; T trait; }; template<> struct Traits<Fruit>{ static string name(int index){ Frulor<Fruit> trait{index}; switch(trait.trait){ case Fruit::apple: return "apple"; case Fruit::orange: return "orange"; case Fruit::pear: return "pear"; default: return "unknown"; } } }; template<> struct Traits<Color>{ static string name(int index){ Frulor<Color> trait{index}; switch(trait.trait){ case Color::red: return "red"; case Color::orange: return "orange"; case Color::green: return "green"; default: return "unknown"; } } };
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Class Template Specialization
You are viewing a single comment's thread. Return to all comments →