Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1027964
  • 博文数量: 288
  • 博客积分: 10306
  • 博客等级: 上将
  • 技术积分: 3182
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-12 17:00
文章分类

全部博文(288)

文章存档

2011年(19)

2010年(38)

2009年(135)

2008年(96)

我的朋友

分类: C/C++

2008-10-18 14:15:12

1.声明与定义
 
class CSingleton
{
public:
 static class CSingleton* Instance();
 static void Release();
protected:
 CSingleton(){};

private:
 static CSingleton* m_pComThread;
};
 
CSingleton* CSingleton::m_pComThread = NULL;
class CSingleton* CSingleton::Instance()
{
 if( NULL == m_pComThread )
  m_pComThread = new CSingleton;
 
 return m_pComThread;
}
void CSingleton::Release()
{
 if( NULL != m_pComThread )
  delete m_pComThread;
}
 
2.使用规则:
在程序结束时要调用Rlease()函数来释放单子对象,从而使单子对象来调用析构函数来释放自己内部申请的内存空间;
 
3.存在问题:
多线程时,在不同的线程中调用实例是否会存在冲突?
阅读(833) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~