Singleton: How should it be used

后端 未结 24 2296
Happy的楠姐
Happy的楠姐 2020-11-22 04:57

Edit: From another question I provided an answer that has links to a lot of questions/answers about singletons: More info about singletons here:

So I have read th

24条回答
  •  深忆病人
    2020-11-22 05:10

    Another implementation

    class Singleton
    {
    public:
        static Singleton& Instance()
        {
            // lazy initialize
            if (instance_ == NULL) instance_ = new Singleton();
    
            return *instance_;
        }
    
    private:
        Singleton() {};
    
        static Singleton *instance_;
    };
    

提交回复
热议问题