Understanding Singleton Design Pattern in C++ with 4 techniques

Singleton pattern is a design pattern which prevents multiple objects of a class to exist. This is a very useful and widely used design pattern as object creation is a costly process (in terms of time) and there are situations that require us to have one object only such as the case of a database connection. In a database connection, we need to initiate the database object once and make all queries through it. Having multiple database objects can give rise to inconsistent database states and hence, needs to be avoided using Singleton Design Pattern.


This is a companion discussion topic for the original entry at http://iq.opengenus.org/singleton-design-pattern-in-cpp/