#ifndef __SINGLETON_H
#define __SINGLETON_H
#pragma warning(push)
#pragma warning(disable:4251)
#include"afxmt.h"
#include <memory>
class Singleton
{
static std::auto_ptr<Singleton> m_pInstance;
protected:
Singleton(){};
//static std::mutex m_Mutex;
static CMutex m_Mutex;
public:
~Singleton(){}
//Return this singleton class' instance pointer
static Singleton* Instance()
{
if(NULL == m_pInstance.get())
{
//加锁
m_Mutex.Lock();
if(NULL == m_pInstance.get())
{
m_pInstance = std::auto_ptr<Singleton>(new Singleton());
}
m_Mutex.Unlock();
}
return m_pInstance.get();
}
};
#define DEFINE_SINGLETON_PUB(cls)\
private:\
static std::auto_ptr<cls> m_pInstance;\
protected:\
cls(){}\
public:\
~cls(){}\
static cls* Instance(){\
if(!m_pInstance.get()){\
m_pInstance = std::auto_ptr<cls>(new cls());\
}\
return m_pInstance.get();\
}
#define IMPLEMENT_SINGLETON_PUB(cls) \
std::auto_ptr<cls> cls::m_pInstance(NULL);
//your declarations that cause 4251
#pragma warning(pop)
#endif
#define __SINGLETON_H
#pragma warning(push)
#pragma warning(disable:4251)
#include"afxmt.h"
#include <memory>
class Singleton
{
static std::auto_ptr<Singleton> m_pInstance;
protected:
Singleton(){};
//static std::mutex m_Mutex;
static CMutex m_Mutex;
public:
~Singleton(){}
//Return this singleton class' instance pointer
static Singleton* Instance()
{
if(NULL == m_pInstance.get())
{
//加锁
m_Mutex.Lock();
if(NULL == m_pInstance.get())
{
m_pInstance = std::auto_ptr<Singleton>(new Singleton());
}
m_Mutex.Unlock();
}
return m_pInstance.get();
}
};
#define DEFINE_SINGLETON_PUB(cls)\
private:\
static std::auto_ptr<cls> m_pInstance;\
protected:\
cls(){}\
public:\
~cls(){}\
static cls* Instance(){\
if(!m_pInstance.get()){\
m_pInstance = std::auto_ptr<cls>(new cls());\
}\
return m_pInstance.get();\
}
#define IMPLEMENT_SINGLETON_PUB(cls) \
std::auto_ptr<cls> cls::m_pInstance(NULL);
//your declarations that cause 4251
#pragma warning(pop)
#endif