QString as parameter in switch case
-
You can use an string as the condition of switch statement, as long as the string class provide an operator such as:
bq.
operator int() constBut, you cannot code something like this!!
bq.
case "A":From ISO C++ 6.4:
bq.
The value of a condition that is an initialized declaration in a switch statement is the value of the declared variable if it has integral or enumeration type, or of that variable implicitly converted to integral or enumeration type otherwise.From ISO C++ 6.4.2
bq.
Any statement within the switch statement can be labeled with one or more case labels as follows:
case constant-expression :
where the constant-expression shall be an integral constant.