Skip to content

Instantly share code, notes, and snippets.

@xkyii
Created May 30, 2012 08:59
Show Gist options
  • Save xkyii/2834741 to your computer and use it in GitHub Desktop.
Save xkyii/2834741 to your computer and use it in GitHub Desktop.
Singleton
#if !defined(UTILHY_SINGLETON_INCLUDED_)
#define UTILHY_SINGLETON_INCLUDED_
//////////////////////////////////////////
// 使用:
// 1, 继承 public CSingleton<T>
// 2, 增加成员量: friend class CSingleton<T>;
//////////////////////////////////////////
template <class T>
class CSingleton {
public:
static T& Instance()
{
static T _instance;
return _instance;
}
protected:
CSingleton(void) {}
virtual ~CSingleton(void) {}
CSingleton(const CSingleton<T>&); //不实现
CSingleton<T>& operator= (const CSingleton<T> &); //不实现
};
#endif // UTILHY_SINGLETON_INCLUDED_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment