1
votes

I'm getting a ginormously long error message. I looked around and it means that my iterator is not the same type as the list it is iterating, but it looks the same to me!

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: error: no match for ‘operator=’ in ‘pos = ((const Map, std::basic_string >*)this)->Map, std::basic_string >::pairList.std::list<_Tp, _Alloc>::begin with _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: note: candidate is: std::_List_iterator, std::basic_string > >& std::_List_iterator, std::basic_string > >::operator=(const std::_List_iterator, std::basic_string > >&)

1

1 Answers

0
votes

The method is const, so pairList.begin() will return a const_iterator.

Change "typename multiPair::iterator pos;" to "typename multiPair::const_iterator pos;"