Domanda

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;
}
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top