<分区>
以下是我的测试代码
#include "test.h"
#include <iostream>
typedef enum{
A = 0,
B
} testEnum;
int main()
{
testEnum e = static_cast<testEnum>(3);
printf("My enum Value : %d\n", (int)e);
int stop = 0;
}
程序输出是我的枚举值:3
现在在程序中,我将数字 3 类型转换为 enum
,然后将其打印为 int
。我猜这应该给出错误或垃圾值或 1(作为枚举最高值)。但是输出是 3。有人可以知道规则是什么以及它是如何工作的。谢谢!