title: Why can't we have non-const class-level static variables?
body: <p>Why does <a href="http://msdn.microsoft.com/en-us/library/acxkb76w.aspx" rel="nofollow">the Visual C++ compiler refuse to compile this code</a>?  </p>
  
  <p>I obviously know that the error is:</p>
  
  <blockquote>
    <p>Error C2864: <code>Singleton&lt;T&gt;::p</code>:<br>
    Only static const integral data members can be initialized within a class</p>
  </blockquote>
  
  <p>but <strong>why</strong>? (i.e. is there a <strong>technical</strong> reason why it is not allowed?)<br>
  Is this compiler-specific behavior or is it mandated by the standard?<br>
  It seems to be fine at the global scope, so why not at the class scope?</p>
  
  <p>It also seems like <a href="https://www.ideone.com/MLFR6" rel="nofollow">not all compilers mind this</a>.</p>
  
  <p>Also, what is the proper way of fixing this?</p>
  
  <pre><code>template&lt;typename T&gt;
  struct Singleton
  {
      static T *p = 0;  // Error C2864
  
      static T *getInstance() { /*...*/ return p; }
  };
  </code></pre>