You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Singleton is a creational design pattern that lets you ensure that a class has only one instance,
4
+
// while providing a global access point to this instance.
5
+
// Appicability:
6
+
// (*) when a class in your program should have just a single instance available to all clients; for example, a single database object shared by different parts of the program.
7
+
// (**) when you need stricter control over global variables.
8
+
9
+
#include<iostream>
10
+
11
+
namespace
12
+
{
13
+
namespaceSingletonPattern
14
+
{
15
+
16
+
/**
17
+
* The Singleton class defines the `GetInstance` method that serves as an
18
+
* alternative to constructor and lets clients access the same instance of this
19
+
* class over and over.
20
+
*/
21
+
classSingleton
22
+
{
23
+
private:
24
+
staticinline Singleton *instance = nullptr;
25
+
staticinlineint num = 0;
26
+
/**
27
+
* The Singleton's constructor should always be private to prevent direct
0 commit comments