title: Where to store Class Specific named constants in C++
body: <p>If you have a class that has some named constants, what is the best practive for storing the constants:</p>
  
  <p><strong>Option 1:  Namespace in Class header</strong></p>
  
  <p>So in my class header I will have:</p>
  
  <pre><code>class myClass
  {
  ...
  ...
  };
  
  namespace NamedConstants
  {
     const string Bucket = "Bucket";
  }
  </code></pre>
  
  <p><strong>Option 2 Member Constants</strong></p>
  
  <pre><code>class MyClass {      // this goes in the class
  private:                          // header file
    static const string Bucket;
    ...
  };
  </code></pre>
  
  <p>... and in the class implementation file:</p>
  
  <pre><code>const string MyClass::Bucket = "Bucket";
  </code></pre>
  
  <hr>
  
  <p>I actually prefer Option 1, considering it to be cleaner: the variable name and value appear together.  Also, if you give the namespace a good name then it can make code more readable when you use constants:</p>
  
  <pre><code>TrafficLight::Green
  </code></pre>
  
  <p>Does anybody see any issue with this method over Option 2?</p>