我收到一条非常长的错误消息。我环顾四周,这意味着我的迭代器与它正在迭代的列表的类型不同,但对我来说它看起来一样!
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 Map, std::basic_string >*)this)->Map, std::basic_string >::pairList.std 中的 'operator=' 不匹配: :list<_Tp, _Alloc>:: 以 _Tp = Pair, 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:注意:候选者是:std::_List_iterator , std::basic_string > >& std::_List_iterator, std::basic_string > >::operator=(const std::_List_iterator, std::basic_string > >&)