title: C++ Singleton undefined reference to
body: <p>I am new to C++ and trying to understand the Singleton Pattern in C++.</p>
  
  <p><strong>myclass.h</strong></p>
  
  <pre><code>#ifndef MYCLASS_H
  #define MYCLASS_H
  
  class Myclass {
      public:
          static Myclass* getInstance();
  
      private:
          Myclass(){}
          Myclass(Myclass const&amp;){}
          Myclass&amp; operator=(Myclass const&amp;){}
          static Myclass* m_instance;
  };
  
  #endif // MYCLASS_H
  </code></pre>
  
  <p><strong>myclass.cpp</strong></p>
  
  <pre><code>#include "myclass.h"
  
  Myclass* Myclass::getInstance() {
      if (!m_instance) {
          m_instance = new Myclass;
      }
  
      return m_instance;
  }
  </code></pre>
  
  <p>The compiler can't compile. I get the following error, on all 3 lines with <code>m_instance</code>:</p>
  
  <p>error: undefined reference to `Myclass::m_instance'</p>