As many people said, this is not possible in vanilla C++. But if you use Qt you can define enums that are registered to the Qt meta system, so you can retrieve enum info during runtime.
The QMetaEnum class provides meta-data about an enumerator.
Use name() for the enumerator's name. The enumerator's keys (names of
each enumerated item) are returned by key(); use keyCount() to find
the number of keys. isFlag() returns whether the enumerator is meant
to be used as a flag, meaning that its values can be combined using
the OR operator.
The conversion functions keyToValue(), valueToKey(), keysToValue(),
and valueToKeys() allow conversion between the integer representation
of an enumeration or set value and its literal representation. The
scope() function returns the class scope this enumerator was declared
in.
class MyClass : public QObject
{
Q_OBJECT
Q_ENUMS(Priority)
public:
MyClass(QObject *parent = 0);
~MyClass();
enum Priority { High, Low, VeryHigh, VeryLow };
void setPriority(Priority priority);
Priority priority() const;
};
Since the whole mechanism uses the Qt meta system, you can only use this approach only for enums, members of QObject derived classes.