A program to demonstrate the concept of overloading unary operator ++ in C++

#include<iostream>
#include<conio.h>
using namespace std;
class Demo
{
int a;
public:
Demo()
{
a=0;
}
Demo(int x)
{
a=x;
}
void operator++()
{
a=a+1;
}
void operator++(int)
{
a=a+1;
}
void display()
{
cout<<“Value of a=”<<a;
}
};
main()
{
Demo d(10);
d++;
++d;
d.display();
getch();
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *