switch [*], ( , ). switch, :
string *convertToString(int i) {
const char *str;
switch(i) {
case 1 : str = "one"; break;
default : str = "error"; break;
}
return new string(str);
}
, , :
const char *values[] = {"error", "one", ... };
string convertToString(unsigned int i) {
if (i >= sizeof(values)/sizeof(*values)) i = 0;
return values[i];
}
, , , . , , .
[*] , , , , . .