Skip to content

Instantly share code, notes, and snippets.

@nopjia
Created April 18, 2014 20:51
Show Gist options
  • Save nopjia/11063843 to your computer and use it in GitHub Desktop.
Save nopjia/11063843 to your computer and use it in GitHub Desktop.
class Singleton {
public:
static Singleton& getInstance()
{
static Singleton instance; // Guaranteed to be destroyed.
// Instantiated on first use.
return instance;
}
private:
Singleton() {}; // Constructor (the {} brackets) are needed here.
// Declare copy constructors to be unaccessible
Singleton(Singleton const&); // Don't implement
void operator=(Singleton const&); // Don't implement
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment