Enumeration enum type name list variable values {}
Yao An enumerated type constant treatment, can not be assigned to them
. 1 enum Weekday {the SUN, the MON, the TUE, WEDs, the THU, the FRI, the SAT}; // enumeration type declaration 2 the SUN = 0 ; // illegal assignment
The default value of enumerated type of starting from 0, 4, 5, ......
You may otherwise defined enumeration element in the statement value
enum Weekday the SUN = { . 7 , the MON = . 1 , the TUE, WEDs, the THU, the FRI, the SAT}; / * enumerated type can declare the value of a particular option, along an increment not previously declared the MON. 1 = the TUE = 2 WEDs . 3 = the THU. 4 = the FRI. 5 = the SAT. 6 = * /
Integer value can not be assigned directly to an enumeration type variable, if you really need to use integer, we need to cast
#include <the iostream> the using namespace STD; enum Weekday the SUN = { . 7 , the MON = . 1 , the TUE, WEDs, the THU, the FRI, the SAT}; int main () { Weekday A; A = 2 ; // not legal a = TUE ; // legitimate A = (Weekday) 2 ; // legitimate COUT << A; }