I want to use switch-case in my program but the compiler gives me this error:
switch expression of type \'QString\' is illegal
How can I us
Late to the party, here's a solution I came up with some time ago, which completely abides to the requested syntax and works with c++11 onwards.
#include
bool isStopWord( QString word )
{
bool flag = false ;
uberswitch( word )
{
case ("the"):
flag = true ;
break ;
case ("at") :
flag = true ;
break ;
case ("in") :
flag = true ;
break ;
case ("your"):
flag = true ;
break ;
case ("near"):
flag = true ;
break ;
case ("all"):
flag = true ;
break ;
case ("this"):
flag = true ;
break ;
}
return flag ;
}
The only differences to be noticed are the usage of uberswitch in place of switch and the parenthesis around the case value (needed, baucause that's a macro).
Here's the code: https://github.com/falemagn/uberswitch