下面主要代码
强枚举类型就是给我们的枚举类型限制相关的类型。
#include <iostream>
using namespace std;
//这里我们可以给enum限定类型
//这里表示我们只能使用char类型
enum color:char{red='A',yellow,green,white};
enum SS{SS1=0,SS2='A',SS3='C'};
int main()
{
color col = yellow;
cout << "Hello World!" << endl;
cout << "current color is "<<col<<endl;
cout << "current color is "<<(char)col<<endl;
SS s = SS1;
cout << "current ss is "<<SS1<<endl;
s = SS2;
cout << "current ss is "<<SS2<<endl;
return 0;
}
运行结果