📄 singleton.h
字号:
/********************************************************************
created: ?
author: Scott Bilas, Game Programming Gems
copyright: Copyright 2003 (C) Scott Bilas
description: Singleton class
*********************************************************************/
#ifndef _SINGLETON_H_
#define _SINGLETON_H_
template <typename T> class Singleton
{
public:
Singleton()
{
//assertex( !m__singleton_ && "Multiple singletons" );
int offset = (int)(T *)1 - (int)(Singleton <T> *)(T *)1;
m__singleton_ = (T *)((int)this + offset);
}
~Singleton()
{
//assertex( m__singleton_ );
m__singleton_ = NULL;
}
static T & GetSingleton() { /*assertex( m__singleton_ );*/ return ( *m__singleton_ ); }
static T * GetSingletonPtr() { return ( m__singleton_ ); }
private:
static T * m__singleton_;
};
template <typename T> T * Singleton <T>::m__singleton_ = 0;
#endif /* _SINGLETON_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -