Suppose to declare a enum type:
enum ImageType
{
Binary,
ByteGray,
ShortGray,
...
}
Is it possible to get the enum constant name like "Binary" from a
configuration file so that
I can change it later?
Yes and no -- it's trivial to invent a file format something like:
Binary = 1
ByteGray = 2
ShortGray = 3
and write a bit of code that can read this and know that "Binary" has
the value 1 afterwards.
The problem is with what you can do with it afterwards -- or more
accurately, with what you CAN'T do with it. You can't use it as a
constant afterwards, so code like:
switch(image_type) {
case Binary:
Because as far as the program cares, Binary is a string that was read in
from a file, and the compiler doesn't know anything about the fact that
you're trying to use it as a constant with the value 1.
OTOH, there are alternatives to that -- for example, you can use an
std::map to associate the value with something like a pointer to an
object or a function, and when you read that value, you can look it up
in the map and find (and execute) what you've associated with the value.
Or can we solve it using other way instead of enum?
The question is what exact problem you're trying to solve.