如何使用C ++将int转换为枚举? [英] How to cast int to enum in C++?
本文介绍了如何使用C ++将int转换为枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
在C ++中将int转换为枚举的通用方式
如何将int转换为C ++中的枚举?
How do I cast an int to an enum in C++?
例如:
enum Test
{
A, B
};
int a = 1;
如何将 a
转换为Test :: A?
How do I convert a
to type Test::A?
推荐答案
int i = 1;
Test val = static_cast<Test>(i);
这篇关于如何使用C ++将int转换为枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文