xml*_*lmx 17 c++ standards enums type-safety c++17
enum class E
{};
int main()
{
E e1{ 0 }; // ok
E e2 = 0; // not ok
// error : cannot initialize a variable of
// type 'E' with an rvalue of type 'int'
}
Run Code Online (Sandbox Code Playgroud)
我的编译器clang 4.0有选项-std=c++1z.
预计E e2 = 0;不行,因为E是强类型的.然而,让我感到惊讶的是E e1{ 0 };应该没问题.
为什么强类型枚举可以用一个整数来初始化static_cast?