Welcome to C ++!
for something even funny try this:
#include <string> int main(int argc, const char *argv[]) { std::string s; s = 3.141592654; return 0; }
why does it compile? The reason is that the rules of the language speak of this.
In this funny case, the “official” explanation of why this example compiles is that it was correct to allow std::string::operator+=(char) (IMO ok and logically from a pragmatic point of view) and therefore also the purpose from char (IMO illogical non-sequitur). But the characters are ints (illogical, but C-legacy), and doubles can be implicitly converted to ints (illogical, but C-legacy). Therefore, in C ++, it is illogical (but legal) to assign a double line.
I don’t feel bad if you don’t know, most of the C ++ programmers that I showed were puzzled by why such stupidity compiles and thinks about other semantics or compiler errors.
In the case of your question, the reason is that the enums in some contexts are similar to ints (probably due to the legacy in the use cases), but not like ints in some other context. This is absurd, but it is what complies with the standard.
If it seems uncomfortable with this, apparently, lack of logic, remember that C ++ is mainly the result of a long history and even a committee (!), So logic really has nothing to do with it. It also implies that you cannot use logic to avoid learning from C ++: no matter how smart you are, you can not guess about the historical accidents and political decisions of the committee.
The high complexity of C ++, the lack of logic in many places, and the presence of undefined behavior daemons instead of runtime error angels are also what IMO basically excludes from learning C ++ by experimentation.
Choose a good book (or several) and read it (them) on the cover ... unfortunately, there is no other way. My suggestions: "C ++ Programming Language" (Stroustrup), "Effective C ++" and "More Effective C ++" (Meyers), "C ++ Frequently Asked Questions" (Cline / Lomow / Girou).
C ++ is a pretty powerful and enjoyable weapon that you can use, but get close to it from the wrong side and it could be the worst of your nightmares. Assuming you can understand this, just using logic is the wrong approach (and not because your logic is weak, but because C ++ is not just logic).