0
Ubuntu Linux 12.04 LTS에서 Qt 5.2.1을 사용하고 있습니다. (*)
표시 줄에 다음과 같은 오류와C++ 클래스 정적 멤버 초기화
#include "rtnamedinstance.h"
// Initialize static members
int RtNamedInstance::_nextInstanceNumber = 0;
QMutex RtNamedInstance::_syncObj(QMutex::Recursive);
RtNamedInstance::RtNamedInstance(QString instanceName)
{
QMutexLocker(&_syncObj); // (*)
// [... other code here ...]
}
컴파일러 종료 : 여기
class RtNamedInstance
{
// [... other code here ...]
public:
static int _nextInstanceNumber;
static QMutex _syncObj;
};
내 구현 (통화 당) : 여기 내 클래스 (.H)의 정의입니다
rtnamedinstance.cpp: In constructor 'RtNamedInstance::RtNamedInstance(QString)': rtnamedinstance.cpp:9:27: error: '_syncObj' declared as reference but not initialized
무엇이 누락 되었습니까?
시작하려면'QMutexLocker' * 변수 *를 정의해야합니다. 지금은 * 임시 *'QMutexLocker' 인스턴스를 생성하는 표현식을 가지고 있습니다. 일단 표현식이 끝나면 (즉각적인) 인스턴스는 파괴되고 실제로 아무런 연산도하지 않는 식으로 아무것도 잠그지 않습니다. –
@ JoachimPileborg : 나는 정말로 어리석은 소년이다 ... 나는 그걸로 몇 분을 낭비했다. 그러나 너는 옳다. QMutexLocker 변수 이름을 입력하는 것을 잊었다! 이제는 잘 작동합니다 ... 감사합니다! –