Singleton Pattern in C++

Most contents are selected from

Suppose we have to use a single object of class throughout the lifetime of an application. in C++, we can declare a global object. Or use a more practical solution, which is to get a single object by declaring a class, which contains only static methods, and this is singleton design pattern. But remember that a class with only static methods and variables are not a good object oriented design.

The Singletons are often used to control access to resources such as database connections or sockets. ♠

By using a private constructor and a static method to create and return an instance of the class is a popular way for implementing Singleton Pattern.