title: Static Map as Class Member in C++
body: <p>I'm having trouble using a static map as a C++ member. My header file is:</p>
  
  <pre><code>class Article
  {
  public:
  //
  static map&lt;string,Article*&gt; dictionary;
  ....
  ....   
  };
  </code></pre>
  
  <p>In my constructor I call the following method first:</p>
  
  <pre><code> void Article::InitializeDictionary()
   {
     #ifndef DICT
     #define DICT
     map&lt;string,Article*&gt; Article::dictionary;
     #endif
   }
  </code></pre>
  
  <p>Based on other posts about this I am supposed to declare the static member but when I try to do this I get the following error:</p>
  
  <pre><code>Error   1   error C2655: 'Article::dictionary' : definition or redeclaration illegal in current scope   c:\.......\article.cpp  88  1
  </code></pre>
  
  <p>If I change the function to the following:</p>
  
  <pre><code>void Article::InitializeDictionary()
  {
      #ifndef DICT
      #define DICT
      Article::dictionary["null"] = 0;
      #endif
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Error   1   error LNK2001: unresolved external symbol "public: static class std::map&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;,class Article *,struct std::less&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;,class std::allocator&lt;struct std::pair&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; const ,class Article *&gt; &gt; &gt; Article::dictionary" (?dictionary@Article@@2V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVArticle@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVArticle@@@std@@@2@@std@@A)
  </code></pre>
  
  <p>Any ideas on what I can do?</p>