unique.cpp
来自「自己写的c++实现的headfirst中的设计模式」· C++ 代码 · 共 36 行
CPP
36 行
/* *单件模式
* 无法实现?链接错误!
*/
#include <iostream>
using namespace std;
class Singleton
{
private:
static Singleton* uniqueInstance;
Singleton();
public:
static Singleton* getStruct()
{
if (uniqueInstance==NULL) uniqueInstance=new Singleton;
else cout << "can not create!";
return uniqueInstance;
}
void function()
{
cout << "fonction!";
}
};
void unique_main()
{
//Singleton s;
//Singleton *s=Singleton::getStruct();
//s->function();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?