hackingcpp / comments

Comments regarding hackingcpp.com
0 stars 0 forks source link

cpp/lang/enumerations #13

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

C++ Enumerations Introduction | hacking C++

A short introduction to enumeration types in C++. Also compares classic C-style enums and modern

https://hackingcpp.com/cpp/lang/enumerations.html

EmmanuelDgz commented 2 years ago

Is static_cast a better approach for conversion?

hackingcpp commented 2 years ago

EnumType(int) and int(enumerator) will both do a static cast in this case. I admit that explicitly writing "static_cast" would be a bit clearer - I think I might change it in the examples. FYI see the rules for such a "functional cast expression" on cppreference: https://en.cppreference.com/w/cpp/language/explicit_cast