title: How can you define const static std::string in header file?
body: <p>I have a class that I would like to store a static <code>std::string</code> that is either truly const or effectively const via a getter.</p>
  
  <p>I've tried a couple direct approaches<br>
   1. <pre><code>const static std::string foo = "bar";</pre></code></p>
  
  <p>2.<pre><code>const extern std::string foo; //defined at the bottom of the header like so 
  ...//remaining code in header
  };  //close header class declaration
  std::string MyClass::foo = "bar"
  /#endif // MYCLASS_H
  </pre></code></p>
  
  <p>I've also tried  </p>
  
  <p>3.<pre><code>protected:
      static std::string foo;
  public:
      static std::string getFoo() { return foo; }</pre></code></p>
  
  <p>These approaches fail for these reasons respectively:<p></p>
  
  <ol>
  <li>error: in-class initialization of static data member <code>const string MyClass::foo</code> of non-literal type</li>
  <li>storage class specified for <code>foo</code> -- it doesn't seem to like combining <code>extern</code> with <code>const</code> or <code>static</code></li>
  <li>many 'undefined reference to' errors generated by other parts of my code and even the return line of the getter function</li>
  </ol>
  
  <p><strong>The reason</strong> I would like to have the declaration within the header rather than source file. This is a class that will be extended and all its other functions are pure virtual so I currently have no other reason than these variables to have a source file.</p>
  
  <p>So how can this be done?</p>