c 11 枚举的新增特性

#include<iostream>
#include <string>
#include <conio.h>

using namespace std;

enum class color{ yellow = 12, blue, red, green };
enum class color_1{ yellow , blue = 5, red, green, huangse, hahah,akjdhf,ahkfjhaskjui,sj };//枚举类,就和普通类相似,
enum class  color_2: unsigned short{ yellow , blue = 46, red, green };                     // 用于区分相同的枚举成员 
enum color_3 { yellow = 12, blue, red, green , adlkfa};
//enum class  color_4: string{ yellow , blue, red, green };//枚举的底层类型必须是整型 

int main(void)
{
    cout << sizeof(color) << endl;     //长度为4
    cout << sizeof(color_1) << endl;   //长度为4 估计是指针是32位 占4个字节
    cout << sizeof(color_3) << endl;   //长度为4 

    int a = 12;
    if(a == yellow)cout << "color_3的yellow" << endl;

    color_1 t = color_1::red;
    int b = (int)t;   // 类型强制转换一下 不然会报错的
    cout << b << endl;
    int x = (int)color::yellow;
    cout << x << endl;
    
    int y = (int)color_2::red ;
    cout << y << endl;
    
    system("pause");
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值