C++ equivalent of Java Enum.valueOf() [duplicate]
Possible Duplicate:
Is it possible to define enumalpha?
Is t开发者_StackOverflow社区here any equivalent of Java Enum.valueOf(string) on C++?
There's no table of names generated by the compiler (unless you count debug information), but if you create one (or use e.g. doxygen which parses the source code and can output such lists in XML format) then you can use a dictionary of some type, such as std::map<string, int>
to turn an identifier into its numeric value.
No, there isn't even the much simpler task of going the other way (enum to string), you'd need to write it yourself
精彩评论