/********************************************************************************
* File Name : Singleton.h
*
* EMail Addr : seakingw@163.com
*
*
* Description : interface for the CSingleton class.
*
********************************************************************************/
#ifndef _SINGLETONE_PATTERNS
#define _SINGLETONE_PATTERNS
* 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();
{
public:
static CSingleton* Instance();
protected:
CSingleton();
CSingleton();
private:
static CSingleton* _instance;
static CSingleton* _instance;
};
#endif
/********************************************************************************
* File Name : Singleton.cpp
*
* EMail Addr : seakingw@163.com
*
* Description : implementation of the CSingleton class.
*
********************************************************************************/
#include "Singleton.h"
* 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();
}
{
if (_instance == NULL)
{
_instance = new CSingleton();
}
return _instance;
}
}
本文介绍了一种使用C++实现单例模式的方法。该方法通过静态成员函数提供全局访问点,并确保类只有一个实例。同时,提供了单例类的声明与定义。
1539

被折叠的 条评论
为什么被折叠?



