enumerate
- Constants can be used to create a symbol, instead const.
enum spectrum {
red, orange, yellow, green, blue, violet, indigo, ultraviolet
};
- spectrum for the new type. The red, orange or the like as a symbolic constant. Their corresponding value of 0 to 7.
- By default, the integer assigned to enumerate the amount of default from zero.
- spectrum band = 2000; // This statement will fail
- spectrum band = blue; // should this assignment
- ++ band; // This statement does not make sense
- band = red + orange; // This statement does not make sense
- Enumeration amount is an integer, it can be promoted to int. But it can not be automatically converted to int enumeration type.
- band = 3; // This statement results in the wrong type, but depending on the implementation
- If the value is valid int enumerated type, it can be cast, convert it to an enumerated type.
- Enumeration is often used to define symbolic constants, rather than defining a new type.
- Assignment operator can use explicit assignment.
enum bits{ one = 1, two = 2, four = 4, eight = 8};
- You can create multiple enumeration values for the same amount.
- c ++ previous version can only be assigned to enumerate int amount, even now you can use long long long.
- Enumeration of the range, a little do not understand.