Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

enums

Possible Duplicate:
Is it possible to define enumalpha?

Is there any equivalent of Java Enum.valueOf(string) on C++?

like image 541
dmessf Avatar asked Aug 13 '26 18:08

dmessf


1 Answers

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.

like image 125
Ben Voigt Avatar answered Aug 16 '26 07:08

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!