title: How to have static data members in a header-only library?
body: <p>What is the best way to have a static member in a non-templated library class,
  without placing the burden of defining the member on the class user?</p>
  
  <p>Say I want to provide this class:</p>
  
  <pre><code>class i_want_a_static_member
  {
      static expensive_resource static_resource_;
  
  public:
      void foo()
      {
          static_resource_.bar();
      }
  };
  </code></pre>
  
  <p>Then the user of the class must not forget to define the static member somewhere
  (as already <a href="https://stackoverflow.com/questions/185844/initializing-private-static-members">answered</a> <a href="https://stackoverflow.com/questions/3536372/defining-static-members-in-c">many</a> <a href="https://stackoverflow.com/questions/1639154/how-to-declare-a-static-const-char-in-your-header-file">times</a>):</p>
  
  <pre><code>// this must be done somewhere in a translation unit
  expensive_resource i_want_a_static_member::static_resource_;
  </code></pre>
  
  <p>I do have an answer below, but it has some disadvantages. Are there better and/or more elegant solutions?</p>