Created
February 11, 2013 21:20
-
-
Save iaintshine/5deb91876f916874b2cc to your computer and use it in GitHub Desktop.
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
#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