📄 singleton.h
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -