Sorry,
maybe I am too stupid, but your code doesn't work for me. I take your code and just changed the name of the class:
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include <QtCore>
#include <QtSql>
class configuration
{
public:
static configuration* instance()
{
if ( !m_instance )
{
mutex.lock();
if ( !m_instance )
m_instance = new configuration;
mutex.unlock();
}
return m_instance;
}
private:
configuration(){};
configuration( const configuration& _instance ){};
static configuration* m_instance;
// [...] some other functions
};
configuration* configuration::m_instance = NULL;
#endif
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include <QtCore>
#include <QtSql>
class configuration
{
public:
static configuration* instance()
{
static QMutex mutex;
if ( !m_instance )
{
mutex.lock();
if ( !m_instance )
m_instance = new configuration;
mutex.unlock();
}
return m_instance;
}
private:
configuration(){};
configuration( const configuration& _instance ){};
static configuration* m_instance;
// [...] some other functions
};
configuration* configuration::m_instance = NULL;
#endif
To copy to clipboard, switch view to plain text mode
When compiling I receive the error (which I don't understand == don't know what to do/where the error could be):
.comp/sw_normal.o: In function `operator delete(void*, void*)':
/usr/include/qt4/QtCore/qatomic_i386.h:62: multiple definition of `configuration::m_instance'
.comp/qvortaro.o:/home/lykurg/Programmierung/qvortaro/src/qvortaro.cpp:194: first defined here
collect2: ld returned 1 exit status
And by the way must it in your example in the wiki not be
Singleton* Singleton::m_Instance = 0;
Singleton* Singleton::m_Instance = 0;
To copy to clipboard, switch view to plain text mode
instead of
Singleton* m_Instance = 0;
Singleton* m_Instance = 0;
To copy to clipboard, switch view to plain text mode
Thanks,
Lykurg
P.s: if I comment the function (on bottom of the file) in qvortaro.cpp:194 out, then this error pointed to now last function on the file.
Bookmarks