Use the concept of operator overloading to overload unary ‘-‘ operator to negate value of variables.
# include <iostream.h>
#include<conio.h>
class unary
{
int x, y, z;
public:
void getdata (int a, int , int c);
void display (void);
void operator - (); // overload unary minus.
};
void unary :: getdata (int a, int b, int c)
{
x = a;
y = b;
z = c;
}
void unary :: display (void)
{
cout<< x << " " << y << " " << z << "\n";
}
void unary ::operator - ()
{
x = -x ;
y = -y ;
z = -z ;
}