How to avoid anonymous enumeration in C++
C++ how to avoid anonymous enumeration, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Reason (reason)
If you can't name an enumeration, the values are not related
If you cannot name enumerations, there is no association between these values.
Example, bad (negative example)
Enum {red = 0xFF0000, scale = 4, is_signed = 1}
Such code is not uncommon in code written before there were convenient alternative ways of specifying integer constants.
Before convenient candidates for defining shaping constants existed, such code was not uncommon.
Alternative (optional)
Use constexpr values instead. For example:
Use constant expressions. For example:
Constexpr int red = 0xFF0000
Constexpr short scale = 4
Constexpr bool is_signed = true; after reading the above, have you mastered how to avoid anonymous enumerations in C++? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!