C++ Program For Pre Increment and Decrement Operator Overloading
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 display();
void operator++();
void operator--();
};
void Test::operator++()
{
++a;
++b;
++c;
}
void Test::operator--()
{
--a;
--b;
--c;
}
void Test::display()
{
cout<<"\n"<<a <<" "<<b<<" "<<c;
}
int main()
{
clrscr();
Test T1(10,20,30);
T1.display();
cout<<endl;
++T1; //T1.operator++()
//--T1; //T1.operator--()
T1.display();
return 0;
}
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

