Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Unary operator Overloading in C++

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class space
{
int x,y,z;
public:
void getdata(int a,int b,int c);
void display();
void operator -();
};
void space::getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void space::display(void)
{
cout<<x<<" "<<y<<" "<<z;
}
void space::operator -()
{
x=-x;
y=-y;
z=-z;
}
void main()
{
clrscr();
space s;
s.getdata(10,-20,30);
-s;
cout<<"s:";
s.display();
getch();
}