Although it would be nice to use an enumeration as a template parameter and recognize each individual enumeration separately, as you wrote it, this will not happen. Instead, I can suggest you declare the following:
template<MyEnum T> void func(){ std::cout << T << std::endl; }
The great thing about C ++ is that the way you structure your templates gives you the Turning complete system. Therefore, you do not need a separate call like this, since you announced that you received each individual enumeration value. You can create a separate function for each value when you need it, and only when you need it.
Now, going to another problem of your question, as @delnan commented, you cannot have two different Enums with the same name. However, you can have a class with a member variable called TWO such that:
struct Foo{ int TWO; }; struct Bar{ int TWO; }; template<typename T> void func(){ std::cout << T::TWO << std::endl; }
Hope this helps.
source share