title: "undefined reference to" with singleton
body: <p>With the following code :</p>
  
  <pre><code>class DBConnection
  {
  // Methodes : private
      private:
          // Constructeur
          DBConnection();
  
          // Destructeur
          ~DBConnection();
  
  // Methodes : public
      public:
          bool open();
          bool close();
  
  // Methodes : public : static
      public:
          static DBConnection * getSingleton();
  
  // Variables
      private:
          static DBConnection * singleton;
  
          QSqlDatabase    conn;
  
          QString         driver,
                          host,
                          userName,
                          password,
                          DBName;
  };
   #endif // DBCONNECTION_HPP
  </code></pre>
  
  <hr>
  
  <pre><code>#include "DBConnection.hpp"
  
  // Initialisation du singleton dans l'espace global, car static
      DBConnection * DBConnection::singleton  = 0;
  
  // Methodes : private
      DBConnection::DBConnection() {
          this-&gt;conn  = QSqlDatabase::addDatabase("QMYSQL");
              this-&gt;conn.setHostName("");
              this-&gt;conn.setUserName("");
              this-&gt;conn.setPassword("");
              this-&gt;conn.setDatabaseName("");
      }
  
      DBConnection::~DBConnection(){};
  
  // Methodes : public
      bool DBConnection::open() {
          bool rep    = this-&gt;conn.isOpen()?true:this-&gt;conn.open();
  
          if(!rep)
              QMessageBox::critical(0, "Erreur critique !", "Impossible d'ouvrir la base de données !");
  
          return rep;
      }
  
  DBConnection * DBConnection::getSingleton() {
          if(singleton == 0)
              singleton   = new DBConnection;
          return singleton;
      }
  </code></pre>
  
  <hr>
  
  <pre><code>#ifndef DAOMYSQLFACTORY_HPP
  #define DAOMYSQLFACTORY_HPP
  
  #include "InterfaceDAOFactory.hpp"
  #include "DAO.hpp"
  
  class DAOMySQLFactory : public InterfaceDAOFactory
  {
  // Methodes : private
      private:
          // Constructeur
          DAOMySQLFactory();
  
          // Destructeur
          ~DAOMySQLFactory();
  // Methodes : public : heritées
      public:
          DAO * getDAOClient();
  
          DAO * getDAOSite();
  
          DAO * getDAOMachine();
  
  // Methode : static
      public:
          static DAOMySQLFactory * getSingleton();
  
  // Variables
      private:
          // Instance unique
          static DAOMySQLFactory * singletonMySQLFactory;
  };
  
  #endif // DAOMYSQLFACTORY_HPP
  </code></pre>
  
  <hr>
  
  <pre><code>#include "DAOMySQLFactory.hpp"
  #include "DBConnection.hpp"
  #include "DAOMySQLClient.hpp"
  
  
  DAOMySQLFactory * DAOMySQLFactory::singletonMySQLFactory = 0;
  
  // Methodes : private
      // Constructeur
      DAOMySQLFactory::DAOMySQLFactory() {}
      // Destructeur
      DAOMySQLFactory::~DAOMySQLFactory() {}
  
  // Methode : static
      DAOMySQLFactory * DAOMySQLFactory::getSingleton() {
          if(singletonMySQLFactory == 0)
              singletonMySQLFactory = new DAOMySQLFactory;
          return singletonMySQLFactory;
      }
  
  // Methodes : public : heritee
  
      DAO * DAOMySQLFactory::getDAOClient() {
          return 0;
      }
  ...
  </code></pre>
  
  <hr>
  
  <pre><code>#include &lt;QApplication&gt;
  
  #include "WinMain.h"
  
  //TEST
  #include "DAOPersistenceFactory.hpp"
  #include "DAO.hpp"
  #include "DAOMySQLFactory.hpp"
  #include "DBConnection.hpp"
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
  //TEST
      InterfaceDAOFactory * idao = DAOPersistenceFactory::getDAOFactory(DAOPersistenceFactory::MySQL);
      DAO * d = idao-&gt;getDAOClient();
      DBConnection::getSingleton();
  
  
      WinMain fen;
      fen.show();
  
      return app.exec();
  }
  </code></pre>
  
  <hr>
  
  <pre><code>#ifndef DAO_HPP
  #define DAO_HPP
  
  #include &lt;QString&gt;
  #include &lt;QStringList&gt;
  #include &lt;QSqlQuery&gt;
  
  class DAO {
  // Methodes : public
      public:
          DAO();
          virtual ~DAO();
  
  // Methodes : public : abstraites
      public:
          virtual QStringList findAll() = 0;
  
  // Variable
      protected:
          QSqlQuery   allQuery;
  };
  
  #endif // DAO_HPP
  </code></pre>
  
  <hr>
  
  <pre><code>#include "DAO.hpp"
  
  DAO::DAO() {}
  
  DAO::~DAO(){}
  </code></pre>
  
  <hr>
  
  <pre><code>#ifndef DAOMYSQLCLIENT_HPP
  #define DAOMYSQLCLIENT_HPP
  
  #include &lt;QString&gt;
  #include &lt;QStringList&gt;
  #include &lt;QSqlQuery&gt;
  
  #include "DAO.hpp"
  #include "DBConnection.hpp"
  
  class DAOMySQLClient : public DAO
  {
  
  // Methodes : public
      public:
          DAOMySQLClient();
      //  DAOMySQLClient(DBConnection * connection);
  //Variables
      private:
          DBConnection    * conn;
  
          QSqlQuery       byIdQuery,
                          byNameQuery;
  };
  
  #endif // DAOMYSQLCLIENT_HPP
  </code></pre>
  
  <hr>
  
  <pre><code>#include &lt;QMessageBox&gt;
  #include &lt;QSqlError&gt;
  #include &lt;QVariant&gt;
  
  #include "DAOMySQLClient.hpp"
  
  
  // Methodes : public
      // Constructeur
      DAOMySQLClient::DAOMySQLClient() {}
  
      // Constructeur
  //  DAOMySQLClient::DAOMySQLClient(DBConnection * connection) {
  //      this-&gt;conn = connection;
  //      this-&gt;conn-&gt;open();
  //      initQueries();
  //  }
  
  ...
  </code></pre>
  
  <hr>
  
  <p>Why i have a </p>
  
  <pre><code>undefined reference to 'DBConnection::getSingleton()'
  collect2:ld returned 1 exit status 
  </code></pre>
  
  <p>in <code>main()</code> and <code>DAOPersistenceFactory::getDAOFactory(DAOPersistenceFactory::MySQL);</code> not whereas it seems to have the same implementation ?</p>