title: c++: Using X Macro to define enum and string array inside class?
body: <p>Using C++ (Visual Studio).  I'm trying to find a solution for converting an enum to a string.  I came across X Macros (<a href="http://drdobbs.com/cpp/184401387" rel="nofollow">http://drdobbs.com/cpp/184401387</a>) 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.</p>
  
  <pre><code>// 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
  }
  </code></pre>
  
  <p>The IDE chokes on the line <code>*colorNameStrings_[] =...</code> I guess because you can't initialize a data member variable in the header file?  How do I get this to work?</p>