设计模式之 Singleton

来源:互联网 发布:linux下强制删除文件 编辑:程序博客网 时间:2024/04/29 13:23
/********************************************************************************
* File Name     :  Singleton.h
*
* EMail Addr    :  seakingw@163.com
*
*
* Description : interface for the CSingleton class.
*
********************************************************************************/
#ifndef _SINGLETONE_PATTERNS
#define _SINGLETONE_PATTERNS
class CSingleton
{
public:
 static CSingleton* Instance();
protected:
 CSingleton();
private:
 static CSingleton* _instance;
};
#endif
 
 
 
/********************************************************************************
* File Name     :  Singleton.cpp
*
* EMail Addr    :  seakingw@163.com
*
* Description : implementation of the CSingleton class.
*
********************************************************************************/
#include "Singleton.h"
CSingleton* CSingleton::_instance = 0;
CSingleton::CSingleton()
{
}
CSingleton* CSingleton::Instance()
{
 if (_instance == NULL)
 {
  _instance = new CSingleton();
 }
 return _instance;
}
 
原创粉丝点击