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,25 @@
#ifndef SINGLETON_H
#define SINGLETON_H
#include <iostream>
#include <string>
class Singleton {
public:
static Singleton &getInstance();
~Singleton();
inline void showMessage() const { std::cout << message;}
inline void updateMessage(const std::string &m) { message = m;}
private:
std::string message;
// Don't allow copying of this class
Singleton() { message = "New singleton\n";}
Singleton(const Singleton &) {}
Singleton &operator=(const Singleton &) {}
};
#endif // SINGLETON_H