The ^ operator is bitwise XOR, not exponet. To square something you're better off with x*x.
Also, this is a horrible - operator. I would expect a - operator to return a point like this:
1 2 3 4 5
point point::operator- (const point& otherpoint) const
{
return point( x - otherpoint.x, y - otherpoint.y );
}
What you are doing would be better accomplished with a Distance function or something similar.
Remember the point of operator overloading is not to be cute or to save on typing. It's to make code more intuitive. If your operator does not do what people would immediately expect it to, then it is a poor operator and should be a function instead.
Remember the point of operator overloading is not to be cute or to save on typing. It's to make code more intuitive. If your operator does not do what people would immediately expect it to, then it is a poor operator and should be a function instead.
Completely agree with this. Intuition would suggest that a point - point operation will deduct both the x and y values of the point class. Although operator overloading is a great feature to know, it's equally as important to know when's best to use it.
And thanks for the ^ clarification. I could vaguely remember it being bitwise related, but couldn't remember how exactly.