namespace Ogre {
// End SJS additions
/** Template class for creating single-instance global classes.
*/
template <typename T> class Singleton
{
protected:

static T* ms_Singleton;

public:
Singleton( void )
{
assert( !ms_Singleton );
#if defined( _MSC_VER ) && _MSC_VER < 1200
int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
ms_Singleton = (T*)((int)this + offset);
#else
ms_Singleton = static_cast< T* >( this );
#endif
}
~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; }
};
}

主要是
int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
让人难以理解,搜了一下,结果如下:
Singleton类要求typename T是它的子类

这一行是确定两者的内存模型偏移
(int)(T*)1 - (int)(Singleton <T> *)(T*)1
1 也可以换成其他的,比如100,1000

内存模型如图
|-----------|<------- ms_Singletion
|   vptr    |
|-----------|
|other  fat-|
|her class  |
|-----------| <-------- * Singleton
|           |
|-----------|
|  others...|
|-----------|

如果typename T 没有多重继承并且没有虚函数
那么可以直接ms_Singleton = static_cast<T *>this;

地址是:
http://bbs.sjtu.edu.cn/bbsgcon?board=C&file=G.1198767949.A
http://www.diybl.com/course/3_program/c++/cppjs/20091224/185434.html