#pragma once #include template class CSingleton { protected: static T* ms_pSingleton; public: CSingleton() { assert( !ms_pSingleton ); /* int offset = (int)(T*)1 - (int)(CSingleton *)(T*)1; ms_pSingleton = (T *)((int)this + offset); */ ms_pSingleton = static_cast (this); } ~CSingleton() { assert( ms_pSingleton ); ms_pSingleton = NULL; } static T* GetInstance() { assert( ms_pSingleton ); return ms_pSingleton; } }; template T* CSingleton ::ms_pSingleton = NULL;