alexismedina
22nd June 2010, 14:50
Hello Devs,
I'm trying to use a singleton class, here's my code (it's really simple):
dao.h
class DAO
{
private:
DAO();
~DAO();
static DAO* m_dao;
public:
static DAO* getInstance();
...
}
dao.cpp
#include "dao.h"
DAO::DAO() { }
DAO::~DAO() { }
DAO* DAO::getInstance() {
if ( ! m_dao ) { // << This causes a crash
m_dao = new DAO();
}
return m_dao;
}
When trying to build the project, I have this message:
dap.cpp:9: undefined reference to `DAO::m_dao'
dao.cpp:10: undefined reference to `DAO::m_dao'
:-1: error: collect2: ld returned 1 exit status
Am I missing something?. I'm using Qt 4.6.32 with vista 64, Qt Creator 1.3.1
I'm trying to use a singleton class, here's my code (it's really simple):
dao.h
class DAO
{
private:
DAO();
~DAO();
static DAO* m_dao;
public:
static DAO* getInstance();
...
}
dao.cpp
#include "dao.h"
DAO::DAO() { }
DAO::~DAO() { }
DAO* DAO::getInstance() {
if ( ! m_dao ) { // << This causes a crash
m_dao = new DAO();
}
return m_dao;
}
When trying to build the project, I have this message:
dap.cpp:9: undefined reference to `DAO::m_dao'
dao.cpp:10: undefined reference to `DAO::m_dao'
:-1: error: collect2: ld returned 1 exit status
Am I missing something?. I'm using Qt 4.6.32 with vista 64, Qt Creator 1.3.1