#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class CSingleton
{
private:
CSingleton() //构造函数是私有的
{
}
static CSingleton *m_pInstance;
public:
static CSingleton * GetInstance()
{
if(m_pInstance == NULL) //判断是否第一次调用
m_pInstance = new CSingleton();
return m_pInstance;
}
};
CSingleton* CSingleton::m_pInstance=NULL;
int main()
{
CSingleton* s1=CSingleton::GetInstance();
system("pause");
return 0;
}
单例模式实例
最新推荐文章于 2021-04-22 17:31:29 发布