Created
December 23, 2013 05:10
-
-
Save Temptationx/8091944 to your computer and use it in GitHub Desktop.
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
class singleton | |
{ | |
private static singleton *_instance = null; | |
protected: | |
singleton() | |
{ | |
if(_instance) | |
{ | |
throw std::logic_error("ss"); | |
} | |
} | |
~singleton() | |
{ | |
if(_instance) | |
{ | |
singleton* instance_copy = _instance; | |
_instance = nullptr; | |
delete instance_copy; | |
} | |
} | |
public: | |
static singleton& getInstance() | |
{ | |
if(!_instance) | |
{ | |
_instance = new singleton; | |
} | |
return *_instance; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment