You are supposed to implement the unary minus '-' operator for struct Point:
struct Point {
int x;
int y;
/* Overloaded
unary minus '-' operator */
};
such that it meets following requirements:
The overloaded operator returns a new Point object and should not modify the object it is called on. For a point, {x, y}, the new returned point should be {-x, -y}:
Point p = {2, 3};
auto np = -p; // Now np is {-2,-3}
The operator can be called inside foo():
void foo(const Point& p) {
auto np = -p; // Should be OK
// ....
}
Point p = {2, 3};
foo(p);
To be consistent with built-in unary minus operator the use of this overloaded operator should not be allowed to create modifiable lvalue:
Point p = {2,3};
-p = {10,20}; // ERROR. Should not be allowed.
Can be repeated multiple times:
Point p = {2,3};
auto pp = -(-p); // pp should be {2,3}
auto np = -(-(-p)); // np should be {-2,-3}
Select the implementation of overloaded unary minus operator that meets all above requirements: