Add example for classic singleton
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
|
||||
#include "singleton.h"
|
||||
#include "singleton.hpp"
|
||||
#include "singleton-pointer.hpp"
|
||||
|
||||
int main(const int argc, const char *argv[])
|
||||
{
|
||||
|
||||
/****************************************************************************/
|
||||
// Meyers Singleton - static getInstance
|
||||
|
||||
// Creates a singleton, initializes message in ctor
|
||||
Singleton &s = Singleton::getInstance();
|
||||
s.showMessage();
|
||||
@@ -12,4 +17,20 @@ int main(const int argc, const char *argv[])
|
||||
// Update already existing Singleton message, show it
|
||||
Singleton::getInstance().updateMessage("Second update\n");
|
||||
s.showMessage();
|
||||
|
||||
/****************************************************************************/
|
||||
// Classic Singleton - pointer getInstance
|
||||
|
||||
|
||||
std::cout << "\n##### ClassicSingleton #####\n\n";
|
||||
|
||||
// Creates a classic singleton, initializes message in ctor
|
||||
ClassicSingleton *classicSingleton = ClassicSingleton::getInstance();
|
||||
classicSingleton->showMessage();
|
||||
// Update already existing ClassicSingleton message, show it
|
||||
classicSingleton->updateMessage("First update\n");
|
||||
ClassicSingleton::getInstance()->showMessage();
|
||||
// Update already existing ClassicSingleton message, show it
|
||||
ClassicSingleton::getInstance()->updateMessage("Second update\n");
|
||||
classicSingleton->showMessage();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user