He doubts operator overload

0

I have doubts about the code below:

Complejo Complejo::operator+ (const Complejo &c){
      Complejo resultado;
      resultado.real = real + c.real;
      resultado.img = img + c.img;
      return resultado;
}

In this operator, what is the difference between "real" and "real"?

    
asked by Chariot 18.09.2018 в 23:09
source

1 answer

2

In the following code you are implementing the sum of the current element with another Complex and return the sum in another element, that is:

Complejo foo = ....;
Complejo foo_2 = ...;
Complejo res = foo + foo_2;

So the task is done using foo , so to access the elements of foo within the class you could use this->algun_valor or simply algun_valor , because just that differentiates real and c.real , real refers to foo and c.real refers to foo_2

    
answered by 18.09.2018 / 23:20
source