哪位高手给一个可继承的单例模式(Singleton)例子

谁给一个可继承的单例模式(Singleton)例子
谢谢

------解决方案--------------------
这种问题咋不问google,来着等不嫌慢呢??

C/C++ code

/////////////////////////////////

//singleton template file

//SingleEx.h

#ifndef SINGLETONEX__H__

#define SINGLETONEX__H__

//File Name : SingletonEx.h

//作用 : 提供单件模板功能(singleton template)

//C++(C++培训 )opyright(C) C++

//Microsoft Visual C++ 6.0 , GCC Ver2.95.3-6 编译通过

//作者:古斌亮

//时间:2002.12.25

//EMail : KingLinux@163.com

template

class CSingletonBase

{

protected:

inline static T* Create(void)

{

if(m_pt==NULL)

{

m_pt=new T();

}

return m_pt;

}

inline static void Free(void)

{

delete m_pt;

m_pt=NULL;

}

protected:

CSingletonBase()

{

}

virtual ~CSingletonBase()

{

delete m_pt;

}

private:

CSingletonBase(const CSingletonBase& sig)

{

}

CSingletonBase& operator = (const CSingletonBase& sig)

{

}

private:

static T * m_pt;

};

template

T* CSingletonBase::m_pt = NULL;

template

class CSingletonEx : private CSingletonBase

{

public:

CSingletonEx()

{

}

virtual ~CSingletonEx()

{

}

public:

virtual T* Instance(void)

{

return CSingletonBase::Create();

}

virtual void Release(void)

{

CSingletonBase::Free();

}

private:

CSingletonEx(const CSingletonEx& sig)

{

}

CSingletonEx& operator = (const CSingletonEx& sig)

{

}

};

#endif //SINGLETONEX__H__

////////////////////////////////

//测试类

//Doc.h

#ifndef CDOC__H__

#define CDOC__H__

class CDoc //测试类

{

public:

CDoc(const std::string name = "NoName"):m_name(name){}

virtual ~CDoc(){}

public:

inline

std::string Name()

{

return m_name;

}

inline

void SetName(const std::string& name)

{

m_name=name;

}

protected:

std::string m_name;

};

#endif //CDOC__H__

////////////////////////////////////

//测试文件

//main.cpp

#include

#include

#include "singletonex.h"

#include "doc.h"

void TestSingletonEx(void)

{

CSingletonEx s;

CDoc *pdoc = s.Instance();

std::cout<Name()< 

pdoc->SetName("pdoc change: My SingletonEx");

CDoc *p2 = s.Instance();

std::cout<Name()< 

p2->SetName("p2 change: SingletonEx ");

std::cout<Name()< 

}

void main(void)

{

std::cout<<"******** Test SingletonEx Start ******** "< 

TestSingletonEx();

}

//the end!!