如何在C++中将整型转换为枚举?
例如:
enum Test
{
A, B
};
int a = 1;
如何将a
转换为Test::A
类型
发布于 2012-07-12 21:33:15
int i = 1;
Test val = static_cast<Test>(i);
发布于 2012-07-12 21:33:16
Test e = static_cast<Test>(1);
发布于 2012-07-12 21:48:55
你的代码
enum Test
{
A, B
}
int a = 1;
解决方案
Test castEnum = static_cast<Test>(a);
https://stackoverflow.com/questions/11452920
复制相似问题