title: C++ - Initializing a static map as a private class member
body: <p>Let's say I was quite bored one late evening and after catatonically staring at the computer monitor for a few hours, I decided to implement an aggregate C++ class to manage colors for drawing pixels, because I've obviously gone mad. For starters, we'll just tell the (probably singleton) <code>ColorManager</code> object what color we want to use and it'll return a <code>Color</code> object, whatever that may be.</p>
  <p>A simple implementation:</p>
  <pre><code>#include &quot;Color.h&quot;
  #include &lt;map&gt;
  
  enum COLOR { RED = 0, BLUE, GREEN, YELLOW, ORANGE, WHITE, BLACK,
      BRICKS_FROM_A_DISTANCE_ON_AN_UNUSUALLY_SUNNY_AFTERNOON,
      // etc
      COLOR_COUNT };
  
  class ColorManager
  {
  public:
      ColorManager();
      ~ColorManager();
      Color getColor(COLOR color) const;
  private:
      typedef std::map&lt;COLOR, Color&gt; ColorMap;
      static ColorMap colorMap;
  };
  </code></pre>
  <p>So, hopefully, this simple code:</p>
  <pre><code>ColorManger colorManager;
  Color blue = colorManager.getColor(BLUE);
  </code></pre>
  <p>should make it real easy for us to do whatever nonsense for which you'd need <code>Color</code> objects.</p>
  <p>The problem is that you need to initialize your static private <code>ColorMap</code> somewhere so that each <code>COLOR</code> enum corresponds to a proper <code>Color</code> object, and VC++ 2010 doesn't seem to like anything you try. So the question is, how and where do I initialize this map?</p>
  <p>Obviously, this is a contrived example, but beyond that, perhaps  defining static variables for a class that functions as a singleton is not worth the trouble. Or, perhaps, I might as well just declare the variable static inside of <code>getColor()</code> since that's the only function that uses it, and just incur the overhead the first time the function is called (although for this simple example, that's not much better than just putting a giant switch statement in there).</p>
  <p>Whatever the case, I appreciate the feedback.</p>