我正在尝试在我的单吨类静态函数之一上实现互斥锁。但收到此错误:
$error:‘m_Mutex’ declared as reference but not initialized
$warning:warning: unused variable ‘m_Mutex’
这是我的代码片段。
========Commondefines.h===========
/**
*@class LockBlock
*This class is used to provide Mutex Lock on thread.
*/
class LockBlock
{
public:
LockBlock(pthread_mutex_t *mutex)
{
lockMutex = mutex;
pthread_mutex_lock(lockMutex);
};
~LockBlock()
{
pthread_mutex_unlock(lockMutex);
lockMutex = NULL;
}
private:
pthread_mutex_t *lockMutex;
};
========MutexImplenation.h======
#include "CommonDefines.h"
class MutexImplementation
{
private:
static pthread_mutex_t m_Mutex ;
public:
static void commonFunction();
};
====MutexImplementation.cpp==========
// Initialize static member of class.
pthread_mutex_t MutexImplentation::m_Mutex = PTHREAD_MUTEX_INITIALIZER;
void commonFunction()
{
LockBlock(&m_Mutex); // Here I am getting this error.
}
任何帮助将不胜感激。谢谢,尤维