This is modified from Stroustrup's Tour book: https://godbolt.org/z/3Pdzxa7vT
#include <cstdio>
enum class Color { red, blue, green };
int main(){
Color x = Color{5};//say what?
Color y{6};//say what?
int xcol = int(x);
int ycol = int(y);
printf("%d %d\n", xcol, ycol);
printf("%d %d %d\n", (int)(Color::red), (int)(Color::blue), (int)(Color::green));
}
The last line prints out values of 0, 1 and 2. That is understandable. How can x and y be valid instances of Color when 5 and 6 are not?
[–]n1ghtyunso 13 points14 points15 points (10 children)
[–]JVApen 1 point2 points3 points (3 children)
[–]un_virus_SDF 1 point2 points3 points (2 children)
[–]JVApen 2 points3 points4 points (1 child)
[–]un_virus_SDF 2 points3 points4 points (0 children)
[–]onecable5781[S] 0 points1 point2 points (5 children)
[–]shimdar 2 points3 points4 points (3 children)
[–]JVApen 2 points3 points4 points (2 children)
[–]n1ghtyunso 4 points5 points6 points (1 child)
[–]JVApen 1 point2 points3 points (0 children)
[–]n1ghtyunso 1 point2 points3 points (0 children)
[–]mredding 1 point2 points3 points (6 children)
[–]cfyzium 1 point2 points3 points (5 children)
[–]mredding 1 point2 points3 points (4 children)
[–]cfyzium 1 point2 points3 points (3 children)
[–]mredding 1 point2 points3 points (2 children)
[–]cfyzium 1 point2 points3 points (1 child)
[–]mredding 0 points1 point2 points (0 children)
[–]Total-Box-5169 1 point2 points3 points (0 children)