Add example for classic singleton

This commit is contained in:
2021-05-11 12:21:03 -04:00
parent 248e48d5c9
commit 9bb2f9867d
6 changed files with 65 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
#include "singleton-pointer.hpp"
// Initialize pointer to instance to null; Allocate on first call to getInstance
ClassicSingleton* ClassicSingleton::instance = nullptr;
ClassicSingleton* ClassicSingleton::getInstance(){
// If the instance is null, return a new one; Otherwise return instance
if(instance == nullptr) instance = new ClassicSingleton;
return instance;
}