Singleton

来源:互联网 发布:php游戏充值平台源码 编辑:程序博客网 时间:2024/05/01 09:51
00001: #pragma once
00002: template<class T>
00003: class Singleton {
00004: public:
00005: static T & getInstance(void) {
00006: static T instance;
00007: return instance;
00008: }
00009: protected:
00010: Singleton() {}
00011: virtual ~Singleton() {}
00012: private:
00013: explicit Singleton(const Singleton<T> &); // disallowed
00014: Singleton<T> & operator = (const Singleton<T> &); // disallowed
00015: };
00016: ////////////////////////////////
00017: class Test : public Singleton<Test> {
00018: private:
00019: Test();
00020: ~Test();
00021: friend class Singleton<Test>;
00022: }
原创粉丝点击