Which of these types CANNOT be used directly as the condition of a C++ switch statement?
Correct answer A. std::string
Explanation
A switch condition must be of integral or enumeration type, or a class type contextually convertible to one, and every case label must be an integral constant expression. char, long and enums all qualify. std::string is a class with no such conversion, so switch(str) does not compile; string comparisons need an if/else chain or a lookup table such as std::map.
Answer checked How we write and check questions
Discussion