新微赢技术网
标题:
请教大家一个关于Singleton的问题
[打印本页]
作者:
黒設會
时间:
2009-11-4 00:06
标题:
请教大家一个关于Singleton的问题
请看一段代码
程序代码:
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
class Singleton
{
protected:
Singleton() {}
private:
Singleton(const Singleton&) {}
Singleton& operator=(const Singleton&) { return *this; }
~Singleton() {}
public:
inline static Singleton *getInstance()
{
return m_pInstance;
}
private:
static Singleton *m_pInstance;
};
Singleton *Singleton::m_pInstance = new Singleton;
class CriSec : public Singleton
{
protected:
CriSec() {}
public:
void init() { InitializeCriticalSection(&m_objCriSec); }
void lock() { EnterCriticalSection(&m_objCriSec); }
void unlock() { LeaveCriticalSection(&m_objCriSec); }
void release() { DeleteCriticalSection(&m_objCriSec); }
private:
CRITICAL_SECTION m_objCriSec;
};
class Foo : public Singleton
{
protected:
欢迎光临 新微赢技术网 (http://bbs.weiying.cn/)
Powered by Discuz! X3.2