2010-09-18 26 views
0

到模板的模板,我新,我試圖實現它使用的地圖(在私有成員)模板類。地圖只能做3件事:插入,交換和運營商=。而且我沒有得到地圖的所有功能..奇怪Behevior當試圖創建包含地圖

下面的代碼:

#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方法時,我得到的是:插入,交換或,operator =。

我如何得到「第一」或「第二」的地圖嗎?

+0

僅供參考,輸入密碼時,最好在代碼粘貼,高亮顯示,然後點擊「101010」按鈕即可實現正確的格式化和語法高亮。 – 2010-09-18 15:55:17

+2

'first'和'秒'不'的std :: multimap'的方法,他們是一個'的std :: pair'的兩個值。要使用'first'和'second',你需要在地圖中有一個[引用]值。您可能想要使用'.find(...)'或在地圖中使用迭代器。這取決於你想要做什麼? – 2010-09-18 15:59:16

+0

感謝重播,我試圖去.begin()值的第一個地圖,我只是無法得到它,我有那裏是插入和交換 – Nadav 2010-09-18 16:03:19

回答