Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is initialization of enum class temporaries with arbitrary values allowed?

Tags:

I came across some code like the following in one the CppCon 2014 talks that confused the heck out of me. The audience accepted it without comment, so I presume that it's legal:

enum class Foo { Bar };

Foo const v1 = Foo(5);

The question is: why does this compile? I would expect compilation to fail and complain that we can't convert an int to a Foo. The slightly modified line below fails with the expected error:

Foo const v1(5);