If I have an C++ enum:
enum Foo { Bar, Baz, Bork, };
How do I tell the compiler to use a uint16_t
to actually store the value of the enum?
EDIT: Does GCC support this feature in its implementation of C++11?
You can change default values of enum elements during declaration (if necessary).
Enumeration or Enum in C is a special kind of data type defined by the user. It consists of constant integrals or integers that are given names by a user. The use of enum in C to name the integer values makes the entire program easy to learn, understand, and maintain by the same or even different programmer.
You can add a new value to a column of data type enum using ALTER MODIFY command. If you want the existing value of enum, then you need to manually write the existing enum value at the time of adding a new value to column of data type enum.
In C#, an enum (or enumeration type) is used to assign constant names to a group of numeric integer values. It makes constant values more readable, for example, WeekDays.
You cannot do this in C++98/03. C++11 does allow you to do it, and without enum class
the way everyone else seems to keep telling you:
enum EnumType : uint16_t { Bar, Baz, Bork, };
Again, you don't have to use enum class
. Not that it's a bad idea, but you don't have to.
Does GCC support this feature in its implementation of C++11?
Which version of GCC? It looks like GCC 4.4 added this functionality, but you should probably look to more recent versions, just for the sake of stability.
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