Created
November 26, 2014 05:09
-
-
Save ofZach/787439f86753b7c6a8c6 to your computer and use it in GitHub Desktop.
singleton template
This file contains 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
#include <stddef.h> // defines NULL | |
template <class T> | |
class Singleton{ | |
public: | |
static T* Instance() { | |
if(!m_pInstance) m_pInstance = new T; | |
assert(m_pInstance != NULL); | |
return m_pInstance; | |
} | |
protected: | |
Singleton(); | |
~Singleton(); | |
private: | |
Singleton(Singleton const&); | |
Singleton& operator=(Singleton const&); | |
static T* m_pInstance; | |
}; | |
template <class T> T* Singleton<T>::m_pInstance=NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
ie: