template<typename T> class singleton_holder : public T {
public:
static singleton_holder<T>& Instance() {
static singleton_holder<T> theOne;
return theOne;
}
private:
singleton_holder() {}
singleton_holder(const singleton_holder& rhs) {}
singleton_holder& operator= (const singleton_holder& rhs) {}
};
C++使用模板实现简单的singleton
于 2009-09-25 22:24:00 首次发布
本文介绍了一种使用模板元编程方式实现的单例模式。通过该方法可以为任意类型创建一个全局唯一的实例,并提供了实例化的静态成员函数。此单例模式通过静态局部变量确保线程安全。
762

被折叠的 条评论
为什么被折叠?



