DEV Community

Discussion on: Bitwise enumerations

Collapse
 
tandrieu profile image
Thibaut Andrieu

Hey, I always found bitwise enums dangerous because they were based on low level consideration, and thus often end up having a Pandora box in your code. I've seen code casting those enums to int to do arithmetics, or adding an intermediate "isHybride = 3" after a few years of entropy, making it half an enum, half a bitflags 😱

But using enum class and redefining operators like you did make things much more robust. Thanks for sharing !

Collapse
 
sandordargo profile image
Sandor Dargo

Thanks for your comment, Thibaut! I'm glad if you found this article useful!

"isHybride = 3"... oh wow :D That's something I'd not expect to see, but yeah, it might happen...

Have a look at this article, Visual Studio might catch such ugly things!