我是模板的新手,我尝试实现一个使用地图(私有成员)的模板类。地图只能做3件事:insert,swap和operator =。我没有得到地图的全部功能..
以下是代码:
#include <map>
using namespace std;
template <class T,class SortKey, class SearchKey>
class GarageDataBase
{
public :
GarageDataBase();
virtual ~GarageDataBase();
const T& Top() const;
bool Add(T data,SortKey key2, SearchKey key2);
T Remove(SearchKey toRemove);
T Find(SearchKey toFind) const;
bool isEmpty()const;
private:
multimap<SortKey,T> firstMap;
multimap<SearchKey,pair<SortKey,T>*> secondMap;
};
template <class T,class SortKey, class SearchKey>
GarageDataBase<T,SortKey,SearchKey>::GarageDataBase()
{
}
template <class T,class SortKey, class SearchKey>
GarageDataBase<T,SortKey,SearchKey>::~GarageDataBase()
{
}
template <class T,class SortKey, class SearchKey>
const T& GarageDataBase<T,SortKey,SearchKey>::Top() const
{
firstMap.
}
在最后一个函数中,当我尝试进入firstMap方法时,我得到的只是:insert,swap或,operator =。
如何在地图中找到“第一个”或“第二个”?
答案 0 :(得分:0)
如果你想用第一个和第二个操作,你必须先从多重图中获得一个元素。您获得了firstMap.find()
或firstMap.begin()
的元素。