I have some enums, and I am saving and loading them to a plain text file.
The only problem is, if I get a lot of these, it would seem to become a pain to create conversion functions for every them (i.e. turning it into an int, then one from an int back to the enum), and it seems to sort of defeat the purpose of the enum.
Is there something I am overlooking here or is this just something I have to deal with?
Yes, I could do it that way, but the point of enums (at least IIRC), is that the underlying numbers shouldn't matter (which it sort of does in this case since I am converting to and from strings basically). Should I convert the stuff to ints and then use a bunch of constints as a reference? i.e.
1 2 3 4 5 6 7 8
//numbers
constint ONE = 1;
constint TWO = 2;
constint THREE = 3;
//...
int some_number = ONE;
The reason I was using them was to prevent someone from setting the value to say 20, or something that didn't make sense.
Yes, that's true, but that doesn't imply that enums can't be used as aliases for actual numbers, rather than as just abstract concepts. If you're going to be doing something like
1 2 3 4 5 6 7
switch (e){
case ZERO:
return 0;
case ONE:
return 1;
//...
}
you might as well take advantage of enums really being integrals.