单例模式的继承实现

#ifndef _HOUSE_DATA_SINGLETON_INTERFACE_H_
#define _HOUSE_DATA_SINGLETON_INTERFACE_H_
//不是线程安全的!!!
template<class T>
class HOUSE_DATA_DLL SingletonInterface
{
public:
	static T* GetInstance()
	{
		m_bSingletonCreating = true;
		static T singleton;
		m_bSingletonCreating = false;

		return &singleton;
	}

protected:
	SingletonInterface() {}
	SingletonInterface(const SingletonInterface&);
	SingletonInterface& operator=(const SingletonInterface&);

	static bool m_bSingletonCreating;
};
template<class T> bool SingletonInterface<T>::m_bSingletonCreating = false;

#endif

另外,单利模式不需要用DLL_EXPORT等来声明


你可能感兴趣的:(单例模式的继承实现)