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'
}
My compiler is clang 4.0
with option -std=c++1z
.
It is expected that E e2 = 0;
is not ok, because E
is strongly-typed. However, what surprised me is that E e1{ 0 };
should be ok.
Why can a strongly-typed enum be initialized with an integer without static_cast
?