Tuesday, November 1, 2016

Post Overloading Increment Operator

Tags

As we all know in operator overloading we overload operators so that they work on objects in same way as they work on built in datatypes.
Now We can overload some operators as Pre or Post
Pre Increment Click Here

In Post Increment we have to supply an integer type argument in operator definition so that compiler can distinguish between Post And Pre.
Following Program Illustrates The Above Concept:
#include<iostream>
using namespace std;
class sample
{
int a;
public:
sample()
{
cout<<"Enter The Number ";
cin>>a;
}
void operator ++(int)
{
a++;
}
void display()
{
cout<<a;
}
};
main()
{
sample n;
n++;
cout<<"After Incrementing  ";
n.display();
}
Output: