设计模式之 Singleton

    技术2022-05-11  95

    /******************************************************************************** * File Name     :  Singleton.h * * EMail Addr    :  seakingw@163.com * * * Description : interface for the CSingleton class. * ********************************************************************************/ #ifndef _SINGLETONE_PATTERNS #define _SINGLETONE_PATTERNS class CSingleton { public:  static CSingleton* Instance(); protected:  CSingleton(); private:  static CSingleton* _instance; }; #endif       /******************************************************************************** * File Name     :  Singleton.cpp * * EMail Addr    :  seakingw@163.com * * Description : implementation of the CSingleton class. * ********************************************************************************/ #include "Singleton.h" CSingleton* CSingleton::_instance = 0; CSingleton::CSingleton() { } CSingleton* CSingleton::Instance() {  if (_instance == NULL)  {   _instance = new CSingleton();  }  return _instance; }  

    最新回复(0)