Luckily for you, literal strings don't always convert to constant integers.
The object of the case statement must be an integral type or something that converts to an integral type.
Try:
enum Species { HUMAN, TROLL, ELF, WIZARD };

The labels of a case statement must be of an integral constant type. Therefore, you can't use any other constants, including literal strings. The most effective technique to overcome this is by using enum types, as hendrixj showed.

02-01-2011, 02:28 PM

jonnin

I always add a max to my enums.

Something like this:

enum Species { HUMAN, TROLL, ELF, WIZARD, Species_Max };

so you can do this:

for(x = human; x < Species_Max; x++)
....

instead of this:

for(x = human; x <= Wizard; x++)

.... my way, if you add in dwarves later on, nothing else changes (max is still max, its just a different number) whereas if you do it the second way, you have to change ALL the loops and other such references.

You can also do this nicely
sometype container[species_max] using the same principles, never change the size, it grows to fit if you add more stuff.