Originally Posted by
Programmer_P
Yes, but as always, you still have to pass the string name of the enum value to get the string name back, which at its core, does NOT make any sense at all. You're getting the string names of enum values by passing those same names? Why not just create a vector of strings manually assigned the literal string names of the enum values, and don't bother with the map at all?
Look at my second example, the dataStr[today]. You will get "Monday". How would you do that with a vector?? The programmer still has to do some work, so it is not a solution, just a way to do it.
Originally Posted by
Programmer_P
When you get that working, let me know...
Look here
I can go as far as (for enums starting with 0)
Code:
#define DECL_ENUM(type) typedef enum type ## _{
#define Enum(value) value
#define END_ENUM(type) } type;
#undef DECL_ENUM
#undef ENUM
#undef END_ENUM
#define DECL_ENUM(type) char* type ##_names[] = {
#define Enum(value) #value
#define END_ENUM(type) ;} /
char* type ## Str(type var) { return type ## _names[type]; }
This is probably not complete, but I don't have the knowledge to make it work. I am sure there are ways. You can now
Code:
DECL_ENUM(Day)
ENUM(Monday),
ENUM(Tuesday),
...
END_ENUM(Day)
...
Day myDay = Monday;
cout << DayStr(myDay) << endl;
Maybe even better make a class with the result
Code:
Day myDay = Day::Monday;
cout << myDay.str() << endl;