How to map enums to their string representation globaly?
Hi,
in my programs I often use enums for integer constants:
Code:
// directions.h
enum Directions
{
west=1,
south=2,
east=3,
nord=4
};
That .h file maybe gets includet in various .cpp files and the enum is used in different classes.
No I sometimes come to the point there I want to display the enum value, so I have to map them somewhere to their string representation.
best thing I came up with yet is to have a std::map<int, string> class memeber in each class what needs the enum-string-representation. the map is filled in the classes ctor.
now that's not a very clear solution because of the redundant code.
I wonder if their is a better solution to this problem or some well known idiom?
Thanks for your ideas!