A unary minus operator implementation that meets given requirements

Question | Jan 26, 2017 | rparekh 

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:

  1. 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}
    
  2. The operator can be called inside foo():

    void foo(const Point& p) {
       auto np = -p; // Should be OK
       // ....
    }
    
    Point p = {2, 3};
    foo(p);  
    
  3. 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.
    
  4. 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: