Add subdirectory for practicing design patterns in C++
+ Add example for singleton
This commit is contained in:
15
cpp/patterns/singleton/singleton.cpp
Normal file
15
cpp/patterns/singleton/singleton.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#include "singleton.h"
|
||||
|
||||
Singleton::~Singleton()
|
||||
{
|
||||
// Delete any allocated data, close any opened files, etc..
|
||||
}
|
||||
|
||||
Singleton &Singleton::getInstance()
|
||||
{
|
||||
// Construct a new singleton if it doesnt exist, return it
|
||||
// + If a static Singleton exists already, just return it
|
||||
static Singleton l;
|
||||
return l;
|
||||
}
|
||||
Reference in New Issue
Block a user