You can set enumerator values explicitly by using the assignment operator:
enum bits{one = 1, two = 2, four = 4, eight = 8};
The assigned values must be integers. You also can define just some of the enumerators explicitly:
enum bigstep{first, second = 100, third};
In this case, first
is 0
by default. Subsequent uninitialized enumerators are larger by one than their predecessors. So, third
would have the value 101
.
Finally, you can create more than one enumerator with the same value:
enum {zero, null = 0, one, numero_uno = 1};
Here, both zero
and null
are 0
, and both one
and numero_uno
are 1
. In earlier versions of C++, you could assign only int
values (or values that promote to int
) to enumerators, but that restriction has been removed so that you can use type long
or even long long
values.
18.118.20.68