Last active
November 20, 2020 15:47
-
-
Save AlexisTM/024d32df6edb34b941b4ccc6feaaa194 to your computer and use it in GitHub Desktop.
The safe singleton in C++
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 { | |
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