October 2011
Beginner to intermediate
1200 pages
35h 33m
English
Originally, the only valid values for an enumeration were those named in the declaration. However, C++ has expanded the list of valid values that can be assigned to an enumeration variable through the use of a type cast. Each enumeration has a range, and you can assign any integer value in the range, even if it’s not an enumerator value, by using a type cast to an enumeration variable. For example, suppose that bits and myflag are defined this way:
enum bits{one = 1, two = 2, four = 4, eight = 8};bits myflag;
In this case, the following is valid:
myflag = bits(6); // valid, because 6 is in bits range
Here 6 is not one of the enumerations, but it lies in the range the enumerations define.
The range is defined as ...
Read now
Unlock full access