klips/cpp/patterns/singleton/singleton-pointer.cpp

12 lines
378 B
C++
Raw Permalink Normal View History

2021-05-11 16:21:03 +00:00
#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;
}