2021-05-11 15:55:21 +00:00
|
|
|
|
2021-05-11 16:21:03 +00:00
|
|
|
#include "singleton.hpp"
|
|
|
|
#include "singleton-pointer.hpp"
|
2021-05-11 15:55:21 +00:00
|
|
|
|
|
|
|
int main(const int argc, const char *argv[])
|
|
|
|
{
|
2021-05-11 16:21:03 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
// Meyers Singleton - static getInstance
|
|
|
|
|
2021-05-11 15:55:21 +00:00
|
|
|
// Creates a singleton, initializes message in ctor
|
|
|
|
Singleton &s = Singleton::getInstance();
|
|
|
|
s.showMessage();
|
|
|
|
// Update already existing Singleton message, show it
|
|
|
|
s.updateMessage("First update\n");
|
|
|
|
Singleton::getInstance().showMessage();
|
|
|
|
// Update already existing Singleton message, show it
|
|
|
|
Singleton::getInstance().updateMessage("Second update\n");
|
|
|
|
s.showMessage();
|
2021-05-11 16:21:03 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
// 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();
|
2021-05-11 15:55:21 +00:00
|
|
|
}
|