singleton.h
来自「龙族普通登陆器源代码.C++.可以正常使用」· C头文件 代码 · 共 55 行
H
55 行
// Singleton.h: definition of the Singleton function.
//
//////////////////////////////////////////////////////////////////////
#ifndef _SINGLETON_
#define _SINGLETON_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
///////////////////////////////////////////////////////////////////////////////
// BEGIN : Singleton 积己 菩畔阑 困茄 努贰胶
template<typename T>
class TSingleton
{
public:
TSingleton()
{
assert(s_pInstance == NULL);
s_pInstance = (T*)((int)this +
(int)(T*)1 - (int)(TSingleton<T>*)(T*)1);
}
virtual ~TSingleton()
{
assert(s_pInstance != NULL);
s_pInstance = NULL;
}
public:
static T& Reference()
{
assert(s_pInstance != NULL);
return *s_pInstance;
}
static T* Pointer()
{
assert(s_pInstance != NULL);
return s_pInstance;
}
private:
static T* s_pInstance;
};
// END
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// BEGIN
template<typename T> T* TSingleton<T>::s_pInstance = NULL;
// END
///////////////////////////////////////////////////////////////////////////////
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?