title: Why can't we declare static variables in the class definition?
body: <p>If I write code that looks like</p>
  
  <pre><code>#include &lt;string&gt;
  class C {
    static const std::string MY_SPECIAL_STRING = "hi";
  };
  </code></pre>
  
  <p>and I try to compile it, even in C++11 mode, g++ will complain:</p>
  
  <blockquote>
    <p>static data member of type 'const std::string' must be initialized out
    of line</p>
  </blockquote>
  
  <p>Why do we have this rule?</p>
  
  <hr>
  
  <p>I mean, I can still kind of 'cheat' and have static variables inside static methods, e.g.:</p>
  
  <pre><code>#include &lt;string&gt;
  class C {
    static const std::string&amp; MY_SPECIAL_STRING() {
      static const std::string&amp; ss("hi");
      return ss;
    }
  };
  </code></pre>
  
  <p>This way, I don't need to put a declaration in a translation unit, and I effectively have the same thing, albeit with uglier syntax.</p>