title: static string constants in class vs namespace for constants [c++]
body: <p>I want to declare string constants that will be used <strong>across various</strong> classes in the project. I am considering two alternatives </p>
  
  <p>Option 1:</p>
  
  <pre><code>#header file 
  class constants{
      static const string const1;
  };
  
  #cpp file
  
  const string constants::const1="blah";
  </code></pre>
  
  <p>Option 2:</p>
  
  <pre><code>#header file 
  namespace constants{
      static const string const1="blah";
  };
  </code></pre>
  
  <p>Just wondering what would be a better implementation.</p>
  
  <p>Already looked at </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/3299765/where-to-store-class-specific-named-constants-in-c">Where to store Class Specific named constants in C++</a></p>
    
    <p><a href="https://stackoverflow.com/questions/2465546/where-to-put-constant-strings-in-c-static-class-members-or-anonymous-namespace">Where to put constant strings in C++: static class members or anonymous namespaces</a></p>
  </blockquote>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>Option 3:</p>
  
  <p>Based on the suggestions from  "potatoswatter" and "sellibitze" i currently have the following implementation?</p>
  
  <pre><code>#header file
  namespace constants{
      extern const string&amp; const1(); //WORKS WITHOUT THE EXTERN  ***WHY***
  };
  
  #cpp file
  namespace constants{
     const string&amp; const1(){static string* str = new string ("blah"); return *str;}
  }
  </code></pre>
  
  <p>I'm including the header file where i need to use the constants. Are there any major cons of this implementation?</p>