Strongly typed enumerations without a clear definition?

I need strong enumeration types. C ++ 0x has this feature, but unfortunately they also require an explicit review:

enum class E {e1, e2, e3};
E x = E::e1; //OK
E y = e1; //error

Sometimes it’s desirable, but sometimes it’s just too detailed. Identifiers can be quite unique in themselves, or an enumeration can already be nested inside a class or namespace.

So I'm looking for a workaround. What would be the best way to declare enum values ​​in an environment?

+5
source share
1 answer

If you want the values ​​displayed in the environment, just add a couple of constants:

enum class E {e1, e2, e3};

const E e1 = E::e1;
const E e2 = E::e2;
const E e3 = E::e3;
+7
source

All Articles