Pre & Post Increment Decrement Operator Overloading in C++ Part-2
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
//Unary Operator overloading (++ and -- post )
#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;
}
Test(){}
Test operator++(); // pre increment
Test operator++(int);//post increment
void operator--(); // Pre decrement
void operator--(int); // post decrement
void display(); // Display value of Object
};
void Test::display()
{
cout<<"\n"<<a <<" "<<b<<" "<<c;
}
Test Test::operator++()
{
++a;
++b;
++c;
return *this;
}
Test Test::operator++(int)
{
Test temp=*this;
a++;
b++;
c++;
return temp;
}
void Test::operator--()
{
--a;
--b;
--c;
}
void Test::operator--(int)
{
a--;
b--;
c--;
}
int main()
{
clrscr();
Test T;
Test T1(10,20,30);
T=T1++;
T.display();
cout<<"\n";
T1.display();
// T1.display();
// T1--; // T1.operator++(int)
// T1.display();
return 0;
}
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

