Can anyone explain the difference between
enum
{Type1,type2}
And
enum class
{Type1, type2}
I use the former often (probably too often without encapsulating enough) but I've never used the second example.
Thanks
enum
An enum
just spills its contents into the enclosing scope, and is basically a const static integer. This means that the first element of any default enum is the same using the == operator.
Enum classes have their own scope, and don't pollute the namespace that they are in. They also make sure that the first element in any enum classes aren't equal.
Prefer enum classes because of their perks if you have a compiler that supports them (any major compiler by now)
I'd you want to learn more go here:
http://en.cppreference.com/w/cpp/language/enum
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With