Skip to content

Instantly share code, notes, and snippets.

@iaintshine
Created February 11, 2013 21:20
Show Gist options
  • Save iaintshine/5deb91876f916874b2cc to your computer and use it in GitHub Desktop.
Save iaintshine/5deb91876f916874b2cc to your computer and use it in GitHub Desktop.
#pragma once
template<typename T>
class Singleton
{
public:
template<typename... Args>
static
T* GetInstance( Args... args )
{
if ( !_instance )
{
_instance = new T(std::forward<Args>(args)...);
}
return _instance;
}
static
void DestroyInstance()
{
delete _instance;
_instance = nullptr;
}
private:
static T* _instance;
};
template<typename T> T* Singleton<T>::_instance = nullptr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment