警告:枚举类型未设定范围
这是代码:程序代码:
#include<iostream> using namespace std; int main(void) { enum Week{ Sunday, Monday, Tuesday}; Week week; int i; for (i = 0; i < 3; i++) { switch (i) { case 0:week = Week(0); break; case 1:week = Week(1); break; case 2:week = Week(2); break; } switch(week) { case Sunday:cout<<"Sunday"<<endl; break; case Monday:cout<<"Monday"<<endl; break; case Tuesday:cout<<"Tuesday"<<endl; break; } } return 0; }
调试时显示:“枚举类型“main::__l2::Week”未设定范围。相比于 "enum",首选 "enum class"”这样一个警告。
我想问一下如何设定范围,不想用"enum class"?