This is how I usually declare such enumerations (unless I need something more unusual, such as automatically converting enumeration names to strings, serialization / deserialization, etc.):
struct Identities { enum Type { UNKNOWN = 1, CHECKED = 2, UNCHECKED = 3 }; }; typedef Identities::Type Identity; struct States { enum Type { UNKNOWN = 0, PENDING = 1, APPROVED = 2, UNAPPROVED = 3 }; }; typedef States::Type Status;
It works in every version of C ++ and is also type safe. Namespaces can also be used instead of structs (but I usually use structs).
source share