@@ -3,12 +3,14 @@
|
||||
|
||||
//做一个单例
|
||||
#include <QHash>
|
||||
|
||||
|
||||
template<typename KeyType,typename ValueType>
|
||||
class SingletonBase
|
||||
{
|
||||
public:
|
||||
SingletonBase();
|
||||
~SingletonBase();
|
||||
// SingletonBase();
|
||||
// ~SingletonBase();
|
||||
void add(const KeyType& key,const ValueType& val)
|
||||
{
|
||||
this->ht[key]=val;
|
||||
@@ -22,6 +24,10 @@ public:
|
||||
return this->ht[key];
|
||||
}
|
||||
|
||||
void initInstance()
|
||||
{
|
||||
if()
|
||||
}
|
||||
protected:
|
||||
|
||||
class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例
|
||||
@@ -34,7 +40,7 @@ protected:
|
||||
}
|
||||
};
|
||||
static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数
|
||||
static QHash<KeyType,ValueType> *ht; *ht;
|
||||
static QHash<KeyType,ValueType> *ht;
|
||||
};
|
||||
|
||||
#endif // SINGLETONBASE_H
|
||||
|
||||
Reference in New Issue
Block a user