title: C++: Undefined reference to instance in Singleton class
body: <p>I'm currently trying to implement a factory as a singleton. I practically used the textbook example of the Singleton pattern. Here's the .h file:</p>
  
  <pre><code>namespace oxygen{
  
  class ImpFactory{
  
  public:
      static boost::shared_ptr&lt;ImpFactory&gt; GetInstance();
  
  private:
      static boost::shared_ptr&lt;ImpFactory&gt; mInstance;
  };
  </code></pre>
  
  <p>and here's the .cpp file:</p>
  
  <pre><code>#include "impfactory.h"
  
  using namespace oxygen;
  using namespace boost;
  
  shared_ptr&lt;ImpFactory&gt; ImpFactory::GetInstance(){
      if (mInstance.get() == 0)
          mInstance = shared_ptr&lt;ImpFactory&gt;(new ImpFactory());
      return mInstance;
  }
  </code></pre>
  
  <p>The code compiles, but I get a linker error:</p>
  
  <blockquote>
    <p>../../lib/oxygen/liboxygen.so.3.2.4: undefined reference to `oxygen::ImpFactory::mInstance'</p>
  </blockquote>
  
  <p>This currently has three students stumped. Any ideas?</p>