title: undefined reference to c++ static field
body: <p>Look at this very basic c++ class:</p>
  
  <pre><code>class MyClass {
   public:
    static std::map&lt;int, std::string&gt; test;
  
    void method1()
    {
       std::cout &lt;&lt; test[1] &lt;&lt; std::endl;
    }
  };
  
  int main()
  {
      MyClass::test[1]="test";  
  
      return 0;
  }
  </code></pre>
  
  <p>As you can see, this very basic class contains a static field.
  But when i am trying to access it, i get this compiler error:</p>
  
  <pre><code>undefined reference to `MyClass::test[abi:cxx11]'
  </code></pre>
  
  <p>In order to make it work, i have tried to create a static method and declare my static field inside this method.
  It works, but it looks ugly.
  I want to understand why my first code does not work and why this second code works...</p>
  
  <pre><code>class MyClass {
   public:
    static std::map&lt;int, std::string&gt;  get_test()
    {
      static std::map&lt;int, std::string&gt; test;
      return test;
    }
  
    void method1()
    {
       std::cout &lt;&lt; get_test()[1] &lt;&lt; std::endl;
    }
  };
  
  int main()
  {
      MyClass::get_test()[1]="test";
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks</p>