您的位置:首页 > 编程语言 > C语言/C++

C++11强枚举类型

2016-09-22 23:48 162 查看
下面主要代码

强枚举类型就是给我们的枚举类型限制相关的类型。

#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;
}


运行结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息