Using C++ (Visual Studio). I'm trying to find a solution for converting an enum to a string. I came across X Macros (http://drdobbs.com/cpp/184401387) which seems to be a reasonable solution but I'm having a hard time getting it to work inside of a class. All the examples I've seen show everything defined outside of a class.
// ColorNames.h
X(Red, "Red"),
X(Blue, "Blue"),
...
// MyClass.h
class MyClass
{
public:
MyClass();
virtual ~MyClass();
#define X(a, b) a
enum Colors {
#include "ColorNames.h"
};
#undef X
#define X(a, b) b
char *colorNameStrings_[] = {
#include "ColorNames.h"
};
#undef X
}
The IDE chokes on the line *colorNameStrings_[] =...
I guess because you can't initialize a data member variable in the header file? How do I get this to work?