Skip to content

Instantly share code, notes, and snippets.

@AlexisTM
Last active November 20, 2020 15:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexisTM/024d32df6edb34b941b4ccc6feaaa194 to your computer and use it in GitHub Desktop.
Save AlexisTM/024d32df6edb34b941b4ccc6feaaa194 to your computer and use it in GitHub Desktop.
The safe singleton in C++
class Singleton {
public:
static Singleton& get() {
static Singleton instance;
return instance;
}
Singleton(Singleton&&) = delete;
Singleton& operator=(Singleton&&) = delete;
Singleton(const Singleton&) = delete;
void operator=(const Singleton&) = delete;
private:
Singleton() {}
~Singleton() {}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment