开发者

C++ equivalent of Java Enum.valueOf() [duplicate]

This question already has answers here: Closed 12 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜