1

I am trying to redefine the == operator in class Regla and i am getting this error in every assignation to iterators :

no match for 'operator=' in 'it2 = (((const std::list<Condicion, std::allocator<Condicion> >*)(+r)) + 4u)->std::list<_Tp, _Alloc>::begin [with _Tp = Condicion, _Alloc = std::allocator<Condicion>]()' 


bool Regla::operator ==(const Regla &r) const{    
  if(this->condiciones.size()!=r.condiciones.size())
    return false;
  if(this->acciones.size()!=r.acciones.size())
    return false;
  list<Condicion>::iterator it,it2;  
  it2 = r.condiciones.begin();
  for(it=condiciones.begin();it!=condiciones.end();it++){
    if((*it)!=(*it2)) return false;
    it2++;
  }
  list<Accion>::iterator it3,it4;
  it4 = r.acciones.begin();
  for(it3=acciones.begin();it3!=acciones.end();it3++){
    if((*it3)!=(*it4)) return false;
    it4++;
  }
  return true;
}
Ankur
  • 5,086
  • 19
  • 37
  • 62
Youssef Khloufi
  • 685
  • 3
  • 13
  • 24
  • On an unrelated note, it's generally considered wise to use pre-increment operators on iterators unless you specifically need the post increment functionality. Because post-increment must create a copy of the iterator to return to you, the pre-increment version is never less efficient and can easily be more efficient. Also, you can do you it2 and it4 assignment and increment in the same locations as the it and it3 counterparts, respectively (using the comma operator). – jpm Nov 19 '12 at 00:19

1 Answers1

1

How about with:

list<Condicion>::const_iterator it,it2;  

The parameter r is passed by const reference, and so is the implicit this because the operator itself is marked as const, so non-const iterators are disallowed for members of both.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625