title: private static const member variable in header vs const variable in cpp
body: <p>Why should I declare a private <code>static const</code> variable in header (and initialize it in cpp) instead of just defining + declaring it in the cpp?</p>
  
  <p>i.e.</p>
  
  <hr>
  
  <p>case1.h</p>
  
  <pre><code>class MyClass
  {
      ...
      private:
          static const MyType some_constant;
  }
  </code></pre>
  
  <p>case1.cpp</p>
  
  <pre><code>const MyType MyClass::some_constant = ...;
  </code></pre>
  
  <hr>
  
  <p>case2.h</p>
  
  <pre><code>//No mention of some_constant at all
  </code></pre>
  
  <p>case2.cpp</p>
  
  <pre><code>const MyType some_constant = ...;
  </code></pre>
  
  <p>Assuming common c++ conventions are followed (1 header &amp; cpp is only associated with 1 class, never <code>#include</code> .cpp file), in both cases, the variable is private to the class, both are initialized before the constructor is called, both provide the function of being a "static class local constant".</p>
  
  <p>Is there any difference between the above two approaches? (And which one is preferable)?</p>