C++ 单例模板
#ifndef _XTHREADDEFINE_H
#define _XTHREADDEFINE_Htemplate<class T>
class singleton
{
public:static T* Instance(){return pInstance;}static T* pInstance;
private://構造函數隱藏起來singleton(){}//將拷貝構造隱藏起來singleton(const singleton&){}//將賦值構造隱藏起來singleton& operator=(const singleton&){}};template<class T> T* singleton<T>::pInstance = new T;#endif
[root@localhost libThreadPool]# ./a.out 0x1646010 0x1646010 0x1646010 0x1646010 0x1646010
[root@localhost libThreadPool]# ./a.out 0x1646010 0x1646010 0x1646010 0x1646010 0x1646010
總結
- 上一篇: 简单的docker命令ubuntu系统
- 下一篇: 前端编码规范,个人感觉bootstrap