Created
July 9, 2014 18:19
-
-
Save petomalina/3d5778cbfdd47570a99d 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
/* | |
* This is the very basic implementation of Singleton | |
* Since C++11, this implementation is thread-safe | |
*/ | |
class Singleton { | |
public: | |
static Singleton& getInstance() { | |
static Singleton instance; | |
return instance; | |
} | |
private: | |
Singleton() { } // do not allow outside constructions | |
Singleton(Singleton const&); // don't allow cloning | |
void operator=(Singleton const&); // don't allow copies | |
}; | |
#define MySingleton Singleton::getInstance() | |
/*Call it now as MySingleton.myMethod(); */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment