Skip to content

Instantly share code, notes, and snippets.

@garrettsickles
Last active November 11, 2017 22:06
Show Gist options
  • Save garrettsickles/8e79bfa912f9de4f2e79770119ef0842 to your computer and use it in GitHub Desktop.
Save garrettsickles/8e79bfa912f9de4f2e79770119ef0842 to your computer and use it in GitHub Desktop.
singleton_c++
class Singleton {
public:
// Singleton Pattern
// Instance() returns a single static instance of the Singleton class.
// This singleton is shared between a single compilation unit.
static Singleton& Instance() {
static Singleton singleton;
return singleton;
}
// Constructor/Destructor
Singleton() {};
~Singleton() {};
// Delete Copy and Move constructors and assign operators
Singleton(Singleton const&) = delete; // Copy constructor
Singleton(Singleton&&) = delete; // Move constructor
Singleton& operator=(Singleton const&) = delete; // Copy assignment
Singleton& operator=(Singleton &&) = delete; // Move assignment
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment