2012-05-12 1 views
1

非常に長いエラーメッセージが表示されます。私は周りを見回しました、そして、それは私のイテレータがそれが反復しているリストと同じ型ではないことを意味しますが、それは私に同じように見えます!同じタイプのイテレータを使用している場合、「演算子は一致しません」

template <typename T1, typename T2> 
class Map 
{ 
    public: 
     Map(); 
     bool contains_key(const T1& key) const; 
    private: 
     T1 key; 
     T2 value; 
     typedef list<Pair<T1, T2> > multiPair; 
     multiPair pairList; 
}; 

template<typename T1, typename T2> 
inline Map<T1, T2>::Map() { } 

template<typename T1, typename T2> 
bool Map<T1, T2>::contains_key(const T1& key) const 
{ 
    typename multiPair::iterator pos; 
    for(pos = pairList.begin(); pos != pairList.end(); pos++) //error 
     if(*pos.get_first() == key) 
      return true; 
    return false; 
} 

map1.h:83:31:エラー:POS =((constの地図、のstd ::のbasic_string> *)この」)で '演算子=' の一致なし - >地図、のstd ::のbasic_string > :: pairList.std :: list < _Tp、_Alloc :: :: _Tp =ペアで始まる、std :: basic_string>、_Alloc = std :: allocator、std :: basic_string>>、std :: list < _Tp、_Alloc > :: const_iterator = std :: _ List_const_iterator、std :: basic_string>> ' /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:114:5:note :候補:: std :: _ List_iterator、std :: basic_string>> & std :: _ List_iterator、std :: basic_string> :: :: operator =(const std :: _ List_iterator、std :: basic_string>> &)

答えて

0

このメソッドはconstなので、pairList.begin()はconst_iteratorを返します。

"typename multiPair :: iterator pos;"を変更します。 "typename multiPair :: const_iterator pos;"に変更します。

+0

ありがとうございます。私は実際にはconstキーワードを理解していない、ちょうどメソッドが戻り値を持っているので、そこにこだわっている。 – user1390757

関連する問題