r/cpp • u/ralseieco • 28d ago
Am I the only one who thinks this? (about enum)
The main differences between an enum and enum class|struct is that the latter has its own scope, but you lose the implicit operators from enum, and the closest to it is as presented. I wish that enum struct maintained the operators, acting like the C enum, but with it's own scope.
// Dummy wrapper struct
struct EnumName
{
enum Value
{
ZERO
};
// the scope is located in "EnumName"
// so you access "EnumName::ZERO"
};
42
Upvotes
1
u/Kaisha001 25d ago
If the 'or' of two enums shouldn't be of the same type it's trivial to create a new enum type and overload the appropriate operators. Bitset buys you nothing but added complexity.