title: Class scope constants: const vs static const
body: <p>For constants of a class, should I use class scope static const, or file scope const?</p>
  
  <p>For example:</p>
  
  <pre><code>// .h
  class C {
    private:
      static const int some_constant_c;
  }
  
  // .cc
  const C::some_constant_c = 10;
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>// .h
  class C {
  }
  
  // .cc
  const some_constant_c = 10;
  </code></pre>
  
  <p>To me, the former one have better semantic meaning that the constant is of a certain class, but the latter one have the advantage not exposing constants to header file.</p>
  
  <p>==============</p>
  
  <p>One follow up question on this:</p>
  
  <p>What if I want my constants be accessed by subclasses. Make sense to put <code>static const</code> in <code>protected</code>? Example follows:</p>
  
  <pre><code>// .h
  class C {
    protected:
      static const int some_constant_c;
  }
  </code></pre>