C++ enum class: Cast to non existing entry
问题 I have this situation on one Project where we have some socket-communication that mainly exchanges characters for flow-control. We cast those characters to an enum class : char in a switch. I was wondering, what might happen, if the other end sends an character that is not in our enum class. I have this mwe: enum class Foo : char { UNKNOWN, ENUM1 = 'A', ENUM2 = 'B', ENUM3 = 'C' }; char bar1() { return 'B'; } char bar2() { return 'D'; } int main() { switch((Foo)bar1()) { case Foo::UNKNOWN:std: