Reputation: 2724
I am using Qt 5.2.1 on Ubuntu Linux 12.04 LTS. Here is the definition of my class (.h):
class RtNamedInstance
{
// [... other code here ...]
public:
static int _nextInstanceNumber;
static QMutex _syncObj;
};
and here my implementation (.cpp):
#include "rtnamedinstance.h"
// Initialize static members
int RtNamedInstance::_nextInstanceNumber = 0;
QMutex RtNamedInstance::_syncObj(QMutex::Recursive);
RtNamedInstance::RtNamedInstance(QString instanceName)
{
QMutexLocker(&_syncObj); // (*)
// [... other code here ...]
}
The compiler exits with the following error on line marked (*)
:
rtnamedinstance.cpp: In constructor 'RtNamedInstance::RtNamedInstance(QString)': rtnamedinstance.cpp:9:27: error: '_syncObj' declared as reference but not initialized
What am I missing?
Upvotes: 1
Views: 1433
Reputation: 2724
As suggested by @JoachimPileborg, I was simply forgetting to type the QMutexLocker variable name... and this confused somehow the compiler...
The correct code is (.cpp):
#include "rtnamedinstance.h"
// Initialize static members
int RtNamedInstance::_nextInstanceNumber = 0;
QMutex RtNamedInstance::_syncObj(QMutex::Recursive);
RtNamedInstance::RtNamedInstance(QString instanceName)
{
QMutexLocker locker(&_syncObj);
// [... other code here ...]
}
Upvotes: 2