Skip to content

Instantly share code, notes, and snippets.

@ar1a
Last active March 28, 2016 07:38
Show Gist options
  • Save ar1a/735e2961ffc6796710da to your computer and use it in GitHub Desktop.
Save ar1a/735e2961ffc6796710da to your computer and use it in GitHub Desktop.
#ifndef SINGLETON_H
#define SINGLETON_H
template<class T>
class singleton
{
public:
static T* instance()
{
return m_instance ? m_instance : (m_instance = new T);
}
protected:
singleton();
~singleton();
private:
singleton(singleton const&);
singleton& operator=(singleton const&);
static T* m_instance;
};
template <class T> T* singleton<T>::m_instance = nullptr;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment