单例模式
来源:互联网 发布:淘宝卖家如何发布宝贝 编辑:程序博客网 时间:2024/06/03 11:16
在设计模式里面最简单的要属单例模式了,我打算把GOF书上的设计模式都实践一遍,先给出单例模式的代码:
#pragma onceclass Singleton{private:static Singleton* instance;Singleton(){}public:static Singleton* Instance(){if(instance==NULL)instance=new Singleton();return instance;}~Singleton(){if(instance!=NULL)delete instance;}};Singleton* Singleton::instance=NULL;下面这是测试代码
#include <iostream>#include <cstdlib>#include "Singleton.h"using namespace std;int main(int argc , char **argv){Singleton *p=Singleton::Instance();Singleton *q=Singleton::Instance();if(p==q)printf("They are equal\n");system("pause");return EXIT_SUCCESS;}
- 单例、单例模式
- 单例模式-多线程单例模式
- 单件模式(单例模式)
- 设计模式------单例模式
- 设计模式------单例模式
- 设计模式-单例模式
- 设计模式 - 单例模式
- 设计模式---单例模式
- 设计模式---单例模式
- PHP模式-单例模式
- 【设计模式】单例模式
- 设计模式-单例模式
- 设计模式----单例模式
- 设计模式--单例模式
- 设计模式-单例模式
- 单例模式(单子模式)
- 设计模式-单例模式
- [设计模式] 单例模式
- POJ1159 Palindrome(最大回文串长度)
- HDU 4602 FFT 终于大致会用FFT了。。
- GridView,repeater整理
- 内部类
- 核心文件&核心转储
- 单例模式
- 黑马程序员——String、StringBuffer、StringBuilder三兄弟
- PHP调试工具Xdebug安装配置教程
- Poj 3292(筛法变形)
- hdu 4605 Magic Ball Game
- JavaScript 框架页面互相访问
- Windows 逻辑坐标和设备坐标
- hive 调用栈
- sgu - 520 - Fire in the Country(bfs + dfs + 博弈)