电子说
枚举概念
枚举的定义格式及初始化
格式
enum 枚举类型名(可省略)
{
枚举成员变量
...........
...........
枚举成员变量
}枚举变量名;
初始化方式1直接声明枚举变量(省略枚举类型名)
enum
{
SUN = 0,
MON = 1,
TUES = 2,
WED = 3,
THURS = 4,
FRI = 5,
SAT = 6,
}WeekDay = SAT;
初始化方式2先声明枚举类型,再定义枚举变量
enum WeekEnumType
{
SUN = 0,
MON = 1,
TUES = 2,
WED = 3,
THURS = 4,
FRI = 5,
SAT = 6,
};
enum WeekEnumType WeekDay = MON;
初始化方式3声明枚举类型名的同时定义枚举变量
enum WeekEnumType
{
SUN = 0,
MON = 1,
TUES = 2,
WED = 3,
THURS = 4,
FRI = 5,
SAT = 6,
}WeekDay = MON;
枚举类型的作用(优点)
全部0条评论
快来发表一下你的评论吧 !