Is the definition of enums in C++ and setting values in random order a valid? Is it used in any well-known code? e.g.:
enum ESampleType{ STPositiveControl='P', STNegativeControl='N', STSample='S' };
VS2008 compiles without warnings. I wonder whether gcc would. In my opinion, it a least harms "least surprise rule" as iterating over all values using
for(int i=STPositiveControl; i<=STSample; ++i)
would fail.
P.S: The rationale for this approach: In my DB application I'm defining wrapper methods. Some columns contain "constants" encoded as single char. I'm trying to make it a little more type safe.
It's a standard and widely used feature. Most of the time (but not always) it will be used to create bitmaps, but it can also be used as you show, to give "printable" values to the enum contants.
It shouldn't surprise anyone who knows C++, as it is widely used.
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