I'm reading Tour of C++ 2nd edition. In section 2.5 Enumerations, it says:
enumclass Color {red, green, blue};
Catching attempted conversions to an enum is a good defense against errors, but
often we want to initialize an enum with a value from its underlying type (by
default, that’s int), so that’s allowed, as is explicit conversion from the
underlying type:
1 2
Color x = Color{5}; // OK, but verbose
Color y {6}; // also OK
But in effect, I get two errors for these two statements!
1 2 3
enumclass Color {red, green, blue};
Color y { 2 }; // Error a value of type "int" cannot be used to initialize an entity of type "Color"
Color x = Color{ 1 }; // Error a value of type "int" cannot be used to initialize an entity of type "Color"
I also looked at the Errata of the book but didn't see it mentioned there!
I don't think VS 2017 enables all C++17 features by default. You might have to use the /std:c++17 (or /std:c++latest) compiler flag to turn this feature on.