c++ - Multimap no match for operator== -


i have multimap inside bar class, unsigned long , reference foo class.

class bar { //etc.         struct map_sort         {             bool operator()(const unsigned long& e1, const unsigned long& e2) const             {                 return (e2 < e1);             }         };      std::multimap<const unsigned long,const foo&, map_sort> m_map;      find_and_erase(const unsigned long var1, const foo& var2); } 

and want retrieve values multimap , erase some.

void bar::find_and_erase(const unsigned long var1, const foo& var2) {     auto = m_map.begin();      (it=m_map.begin(); it!=m_map.end(); ++it)     {         const unsigned long first = (*it).first;         const foo& second = (*it).second;         if((first == var1) && (second == var2)) //<----error no match operator==             m_map.erase(it);     } } 

question

how can compare (second == var2) ?

(what want find entries multimap, , delete ones on find_and_erase() function, matches function argument. don't know if there easier solution this)

define equality function foos:

bool operator==(const foo& a, const foo& b) {     // return whether foos equal } 

if define one, you'll want define != completeness:

bool operator=!(const foo& a, const foo& b) { return !operator==(a,b); } 

also, per n.m.'s comment, given have multimap should take advantage of it:

void bar::find_and_erase(const unsigned long var1, const foo& var2) {     auto = m_map.equal_range(var1);     (auto = its.first; != its.second; ++it) {         if (it.second == var2) {             m_map.erase(it);         }     } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -