In fact, you can use anything other than integers (sometimes denoted by integer types) if the test objects determine the conversion to integer.
String object does not work.
However, you can create a map with string keys (check that the comparison is well-processed) and pointers to classes that implement some interface as values:
class MyInterface {
public:
virtual void doit() = 0;
}
class FirstBehavior : public MyInterface {
public:
virtual void doit() {
}
}
class SecondBehavior : public MyInterface {
public:
virtual void doit() {
}
}
...
map<string,MyInterface*> stringSwitch;
stringSwitch["val1"] = new FirstBehavior();
stringSwitch["val2"] = new SecondBehavior();
...
stringSwitch[val]->doit();
A bit longer to implement, but well designed.