Skip to main content

Posts

Showing posts from September, 2022

Overloading Unary operator

 Overloading Unary operator In the following program the unary minus operator is used. A minus operator used as a unary, takes just one operand. /* Program that Shows how the unary minus operator is overloaded. */ #include<iostream> using namespace std; class simple {     int x;     int y;     int z;   public:       void getdata(int a, int b, int c);       void display(void);      void operator-();   //overload unary minus }; void space::getdata(int a, int b, int c) {     x=a;      y=b;     z=c; } void space::display(void) {     cout<<"x="<<x<<" ";      cout<<"y="<<y<<" ";      cout<<"z="<<z<<" "; } void space::operator-() {     x=-x;     y=-y;     z=-z; } int main(){      space S;      S.getdata(...