3 ms·
This. Only `enum class` gives you a strongly-typed guarantee, `enum` can happily implicitly decay to `int` without any kind of warning. Lots of C libraries use
by qalmakka 6y ago
This. Only `enum class` gives you a strongly-typed guarantee, `enum` can happily implicitly decay to `int` without any kind of warning. Lots of C libraries use `int` frequently together with enums without any sort of care, and it's too late to change this behaviour without creating an interoperability nightmare. The fact that `int` is not implicitly convertible to an enum type at least still saves you from a death from thousand cuts when a wrong value manages to get into an enum.
The only sane way is to consider `enum` as a deprecated construct in C++ and use it as sparingly as possible, preferably only when interoperability with C makes them unavoidable.
- quietbritishjim 6y agoThis article is about code that will directly be compiled by both a C and C++ compiler, so indeed `enum class` is not an option here.