C++ different singleton implementations

前端 未结 5 1728
遇见更好的自我
遇见更好的自我 2020-12-21 16:16

I usually implement the singleton pattern this way :

class Singleton
{
    public:
        virtual ~Singleton() {}

        static Singleton& GetInstance         


        
5条回答
  •  悲哀的现实
    2020-12-21 16:57

    The second implementation is wrong. The default constructor should be private. As it is, it is not a singleton per se. Besides that, the differences between the implementations are mentioned in @Andrew and @Brady answers.

提交回复
热议问题