Multiple choice

What changes are to be made in prototype/signature of unary minus(-) operator overloading function to convert it into friend function? Declaration : void operator –(); Definition :void space:: operator –(){ x=-x; y=-y;}; where space is class name and x and y are integer variables.

  1. Declaration : friend void operator –(space &s); Definition :void operator –(space &s){ s.x=-s.x; s.y=-s.y;}

  2. Declaration : friend void operator –(); Definition : void space operator –(){ x=-x; y=-y;}

  3. Declaration : friend void operator –(space &s); Definition : void operator –(space &s){ x=-x; y=-y;}

  4. Unary minus operator cannot be overloaded using friend function

  5. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

There is no need to use scope resolution operator if function is defined as friend. We have to pass the arguments by reference.