The question is a continuation of this question. According to the algorithm, I need to create a new disjunct based on the other two and place it at the end of the set. For this, in my program, the first procedure creates a new instance (? I hope was not mistaken in terminology) of the class disjunct, based on the current one, and the operator overload = should assign it to the variable d3. The error occurs when I try to assign the value d3 = d2.construct_resolution (d1, g);

disjunct disjunct::construct_resolution(disjunct& right_disj, signed char &kontrar_couple){ disjunct *resolution = new disjunct; std::list<signed char>::const_iterator left_it; for(left_it = disj.begin(); left_it != disj.end(); left_it++){ signed char literal = *left_it; signed char not_literal = kontrar_couple | 0x80; if((literal != kontrar_couple) && (literal != not_literal)){ resolution->addLiteral(literal); } } return resolution; } disjunct& disjunct::operator =(disjunct& disj){ if (this == &disj) { return *this; } *this->clear(); std::list<signed char>::iterator i; for(i = disj.disj.begin(); i != disj.disj.end(); i++){ signed char literal = *i; *this->addLiteral(literal); } return *this; } 

In the main function I write:

  disjunct d1; disjunct d2; disjunct d3; d3 = d2.construct_resolution(d1, g); // g - переменная типа signed char, (является контрарной парой для d2 и d1) 

I get the error:

main.cpp: 54: 39: error: no match for 'operator =' in '; d3 = disjunct :: construct : 39: note: candidate is:
disjunct.h: 29: 15: note: disjunct & disjunct :: operator = (disjunct &)
disjunct.h: 29: 15: note: no disjunct 'to' disjunct & '

  • Yes, I rewrote it, it all worked. disjunct & disjunct :: operator = (disjunct disj) {if (this == & disj) {return * this; } clear (); std :: list <signed char> :: iterator i; for (i = disj.disj.begin (); i! = disj.disj.end (); i ++) {signed char literal = * i; addLiteral (literal); } return * this; } Could you explain the theoretical part. Why is it not necessary to transfer the link in this case? PS It's strange that my g ++ didn't give any errors to this place) - Egor Sokolov
  • @alexlz, thank you, translate your comment in response and I will mark it as accepted - Yegor Sokolov
  • And why should he follow the link? Quite the right part of the assignment. And why does not swear on return resolution; In construct_resolution - it is not clear, because the return value should be. disjunct &, and resolution - * disjunct. And with the priorities of operations * and -> not everything is also “intuitively clear” - alexlz

1 answer 1

And why

 disjunct& disjunct::operator =(disjunct& disj){ 

but not

 disjunct& disjunct::operator =(disjunct disj){ 

By the way, there is something else for some reason *this-> . What should that mean? I do not eat g ++