#include <cassert>

template <typename T> class Singleton
{
    static T* ms_Singleton;

public:
    Singleton( void )
    {
        assert( !ms_Singleton );
        int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
        ms_Singleton = (T*)((int)this + offset);
    }
   ~Singleton( void )
        {  assert( ms_Singleton );  ms_Singleton = 0;  }
    static T& GetSingleton( void )
        {  assert( ms_Singleton );  return ( *ms_Singleton );  }
    static T* GetSingletonPtr( void )
        {  return ( ms_Singleton );  }
};

template <typename T> T* Singleton <T>::ms_Singleton = 0; 


template <typename T> T* Singleton <T>::ms_Singleton = 0;

相关文章:

  • 2022-12-23
  • 2021-04-11
  • 2021-10-21
  • 2021-10-28
  • 2021-09-21
  • 2018-07-05
猜你喜欢
  • 2021-09-30
  • 2021-09-28
  • 2022-12-23
  • 2021-12-02
  • 2021-11-25
  • 2021-09-02
  • 2021-11-24
相关资源
相似解决方案