Skip to content

Instantly share code, notes, and snippets.

@petomalina
Created July 9, 2014 18:19
Show Gist options
  • Save petomalina/3d5778cbfdd47570a99d to your computer and use it in GitHub Desktop.
Save petomalina/3d5778cbfdd47570a99d to your computer and use it in GitHub Desktop.
/*
* 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