摘要: 本文演示了如何无需显式声明一个类,直接通过“类名::GetInstance()”方式获得单类实例的指针。#include <iostream>using namespace std;// Singleton 基类,提供 GetInstance() 方法,获得T类的单实例指针template <class T>class Singleton{public: static T* GetInstance(){ static T instance; // 利用 static 从而获得单类型的实例 return &instance; }protected: ... 阅读全文
posted @ 2012-06-27 17:49 ET民工[源自火星] 阅读(1024) 评论(0) 推荐(0) 编辑