【发布时间】:2011-08-07 17:02:46
【问题描述】:
如果我有一个强类型枚举,比如基础类型 int,是否可以将不匹配任何枚举数的 int 值强制转换为枚举类型?
enum e1 : int { x = 0, y = 1 };
enum class e2 : int { x = 0, y = 1 };
int main() {
e1 foo = static_cast<e1>(42); // is this UB?
e2 bar = static_cast<e2>(42);
}
【问题讨论】: