Cannot access private member in singleton class destructor

前端 未结 5 934
感动是毒
感动是毒 2020-12-21 05:24

I\'m trying to implement this singleton class. But I encountered this error:

\'Singleton::~Singleton\': cannot access private member declared in class \'Singleton\'

5条回答
  •  爱一瞬间的悲伤
    2020-12-21 05:39

    class Singleton
    {
         static Singleton *pInstance = NULL;  
         Singleton(){};
    
         public:
    
        static Singleton * GetInstance() {
    
              if(!pInstance)
              {
                   pInstance = new Singleton();
              }
              return pInstance;
         }
    
         static void  RemoveInstance() {
    
              if(pInstance)
              {
                   delete pInstance;
                   pInstance = NULL;
              }
    
         }
    };
    

提交回复
热议问题