// enum is just like struct key word
enum week{sunday, monday, tuesday, wednesday, thirsday, friday, saturday, }; // extra comma in the end, but it is not necessary
int main(int argc, char* argv[])
{
cout<<sunday<<endl;
cout<<monday<<endl;
// cpp style
week weekday;
// weekday = 4;// fail,can't convert from 'int' to 'week'
weekday = (week)4;// OK
weekday = static_cast<week>(4);// OK
int a = weekday;// OK, it is right to convert from 'week' to 'int'
// c style
enum week weekday_1 = monday;// enum is just like struct between c and cpp
return 0;
}
enum
最新推荐文章于 2022-10-25 15:16:42 发布