Created
May 30, 2012 08:59
-
-
Save xkyii/2834741 to your computer and use it in GitHub Desktop.
Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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