CC++

CC++,第1张

CC++ 代码
#include 
using namespace std;

//! C++11 作用域内枚举体的一些特性
//!	1.C++11新版枚举体,增加关键字class,可以避免small,big相同的符号冲突
enum class eggs{ small, big };
enum class he{ small, big };

//! 2.可以指定枚举体底层类型,底层类型为short
//enum class : short Workday{ Monday, Tuesday };

int main()
{
	//! 3.赋值
	eggs e = eggs::small;

	//! 4.类型转换增加安全性,避免隐式转换,可以显示转换
	int a = int(e);

	cin.get();
	return EXIT_SUCCESS;
}
参考书籍

C++ Primer Plus(第6版)——10.6.2 作用域内枚举(c++11)

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5670353.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存