please take your time viewing the code below and answer my queries regarding it
class Vector
{
public:
int x, y;
/* Constructor / destructor / Other methods */
Vector operator + (Vector & OtherVector);
Vector & operator += (Vector & OtherVector);
};
Vector Vector::operator + (Vector & OtherVector) // LINE 6
{
Vector TempVector;
TempVector.x = x + OtherVector.x;
TempVector.y = y + OtherVector.y;
return TempVector;
}
Vector & Vector::operator += (Vector & OtherVector)
{
x += OtherVector.x;
y += OtherVector.y;
return * this;
}
Vector VectorOne;
Vector VectorTwo;
Vector VectorThree;
/* Do something with vectors */
VectorOne = VectorTwo + VectorThree;
VectorThree += VectorOne;
This code was taken off from a book but its not explained very well in there. Specifically I am not able to understand the program from line 6. Neither the constructor nor the operator overloading. Please explain how are operator overloading and the copy constructors working in this program.
Edit: Why are we using the reference operator?