Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
//Unary Operator overloading (- operator)
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Test
{
int a,b,c;
public:
Test(int a,int b,int c)
{
this->a=a;
this->b=b;
this->c=c;
}
void operator-();
void display();
};
void Test::operator-()
{
a=-a;
b=-b;
c=-c;
}
void Test::display()
{
{
cout<<a <<" "<<b<<" "<<c;
}
}
int main()
{
clrscr();
Test T1(50,70,90);
Test T2(100,20,34);
T1.display();
T2.display();
cout<<endl;
-T1;
-T2;
T1.display();
T2.display();
}