enum Days // Declare enum type Days
{
saturday, // saturday = 0 by default
sunday = 0, // sunday = 0 as well
monday, // monday = 1
tuesday, // tuesday = 2
wednesday, // etc.
thursday,
friday
} today; // Variable today has type Days
int tuesday; // Error, redefinition of tuesday
enum Days yesterday; // Legal in C and C++
Days tomorrow; // Legal in C++ only
yesterday = monday;
int i = tuesday; // Legal; i = 2
yesterday = 0; // Error; no conversion
yesterday = (Days)0; // Legal, but results undefined
下面这样也可以:
enum
{
AAA = -200,
BBB =50
};