c++单例
来源:互联网 发布:c语言 矩形 rect 编辑:程序博客网 时间:2024/06/09 23:05
网上找的,记录一下
#pragma oncetemplate <class T>class Singleton{public: static inline T* instance(); private: Singleton(void){} ~Singleton(void){} Singleton(const Singleton&){} Singleton & operator= (const Singleton &){} static std::auto_ptr<T> _instance;}; template <class T>std::auto_ptr<T> Singleton<T>::_instance; template <class T> inline T* Singleton<T>::instance(){ if( 0== _instance.get()) { _instance.reset ( new T); } return _instance.get();}//Class that will implement the singleton mode,//must use the macro in it's delare file#define DECLARE_SINGLETON_CLASS( type ) \ friend class std::auto_ptr< type >;\ friend class Singleton< type >;
用法是:
类声明头部加入
DECLARE_SINGLETON_CLASS(TaskManager);
头文件声明调用宏(非必要)
#define TaskManagerInstance (Singleton<TaskManager>::instance())
0 0
- C#单例模式
- C#-单例模式
- 单例模式(C++)
- 单例(c++)
- 【C++】单例模式
- Objective-C 单例
- [C++]单例模式
- 单例模式(C++)
- Objective-C单例
- C ++的单例模式
- 【C++】Chapter17:单例模式
- Object-c单例模式
- Objectove-c单例模式
- Objective-C单例实现
- Objective C--单例模式
- Objective C--单例模式
- Objective C 单例模式
- Objective-C 中的单例
- Linux命令整理--pwd命令
- <iOS>swift简单控件的创建
- c++存取dat数据
- FileZilla FTP Server在win2008安装及防火墙设置
- leetcode-Power of Two
- c++单例
- Socket 编程(二)
- View的getScrollX(),getScrollY(),getScrollBy(),getScrollTo()
- android权限大全
- 通过CLLocationManager定位当前坐标和城市
- 欢迎使用CSDN-markdown编辑器
- javascript 的几种使用多行字符串的方式
- C#的textbox的LostFocus事件重复执行
- Freemarker list对象取前几条数据