title: Why do I get an "Undefined reference error" when implementing a singleton class?
body: <p>I'am trying to implement a method that returns me an instance of the class, but it's is crashing when it tries to create the instance at the first time. I don't know how to implement the singleton in C++/QT</p>
  
  <p>Main</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include "carro.h"
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      Carta* nueva;
      nueva-&gt;getInstance();
      nueva-&gt;setColor("rojo");
      cout &lt;&lt; nueva-&gt;getColor() &lt;&lt; endl;
  
      return a.exec();
  }
  </code></pre>
  
  <p>Carro.h</p>
  
  <pre><code>#ifndef CARRO_H
  #define CARRO_H
  
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  class Carta{
  
  private:
      string cara; //valor
      string palo; //simbolo
      string color;
      string direccion;
  
      static Carta* m_instance;
  
  public:
      //constructor
      Carta(){
      }
  
     static Carta* getInstance(){
         if(!m_instance){
             m_instance = new Carta;
         }
         return m_instance;
      }
  
      string getDireccion(){
          return direccion;
      }
  
      void setColor(string pcolor){
          color = pcolor;
      }
  
      string getColor(){
          return this-&gt;color;
      }
  
      string getPalo(){
          return this-&gt;palo;
      }
  
      string getCara(){
          return this-&gt;cara;
      }
  
      //print
      string print(){
          return (cara + " de " + palo + " Color: "+color);
      }    
  };
  
  #endif // CARRO_H
  </code></pre>