Original Post
Hi,
Can anyone explain to me how assignment operator overloading works?
For example if I did this:
Class Vector
{
...
Vector operator+=(Vector otherV);
point[3];
...
}
Vector Vector::operator+=(Vector otherV)
{
Vector newVector;
newVector.point[0] = otherV.point[0];
newVector.point[1] = otherV.point[1];
newVector.point[2] = otherV.point[2];
return newVector;
}
and If I use it like this:
Vector v1(1,1,1), v2(2,2,2);
v1 = v2;
"v1" will not change. I know this doesn''t work, but why doesn''t it work?
The correct way would be directly modify the "point" member instead of
creating a new vector variable then returning it.
Any thoughts?
Thanks.