title: Why define constants in a class versus a namespace?
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/4977330/static-members-class-vs-normal-c-like-interface">Static members class vs. normal c-like interface</a></p>
  </blockquote>
  
  <p>I am looking at somebodies code and there are several dozen constants defined in a class like this:</p>
  <pre><code>// header file
  
  class Defines
  {
  public:
      static const int Val1;
      static const int ValN;
      static const char* String1;
      static const char* StringN;
  ...
  }
  
  // .CPP
  const char* Defines::String1 = &quot;some value&quot;
  etc.
  </code></pre>
  <p>Is there some reason to do things this was as opposed to using a namespace instead?
  Are there advantages/disadvantages of one over the other</p>
  <p>--------- Edit ----------</p>
  <p>I'm sorry, I obviously should have pointed this out explicitly, as nobody has inferred it from the name of the class - which is &quot;Defines&quot;. i.e. these constants are not associated with a particular class, there has been a class created specifically just to hold constants and nothing else, that is all the class Defines contains.</p>
  <p>My question is not why should you place constants in a particular class, the question is is there any value in collecting dozens of them together and placing them <em>in a class</em> whose only purpose is to collect together constants, as opposed to collecting them together in a namespace, or just collecting them together in a header file specifically for that purpose etc.</p>
  <p>(There is no currently existing namespace in the project therefore potential issues of polluting the namespace as mentioned in answers are not relevant in this case.)</p>
  <p>----- 32nd edit -----------</p>
  <p>and a follow up question ---
  is placing
  const char* Defines::StringN = &quot;Somevalue&quot;</p>
  <p>in the .h file inefficient versus placing it in the .cpp file?</p>