| 发表于:2008-01-21 20:52:12 楼主 |
enum week : char{ monday='m', tuesday='t', wednesday='w',thursday='t', friday='f', saturday='s', sunday='s'}things; things=sunday; cout < <things; 有错啊 error c2593: 'operator < <' is ambiguous ivor horton's beginning visual c++? 2005 enumeration constants are type int by default, but you can also choose to specify the type explicitly by adding a colon and the type name for the constants following the enumeration type name in the declaration. you can specify the type for the enumeration constants as any of the signed or unsigned integer types: short, int, long, and char, or as type bool. thus, you could define the enumeration representing days of the week as: enum week: char{ monday, tuesday, wednesday, thursday, friday, saturday, sunday}; here the enumeration constants will be of type char with the first constant as 0. however, with the constants as type char you might prefer to initialize them explicitly, like this: enum week : char{ monday='m', tuesday='t', wednesday='w', thursday='t', friday='f', saturday='s', sunday='s'}; now the values for the constants reflect a little more what they represent, although they do not distinguish between thursday and tuesday or between saturday and sunday. there is no problem with having duplicate values for the constants, but of course, all the names must be unique. here's an example of an enumeration with bool constants: enum state : bool { on = true, off}; because on has the initial value true, off will be false. if there were subsequent enumerations constants specified, they would alternate in value by default |
|
|
|
|