Operator Overloading In CPP

Operator Overloading: Behavior can be changed by using operator overloading. And also this can be used to redefine the meaning of the operator.

#include<iostream.h>
#include<conio.h>


class A
{
public:
int i;
void operator ++()
{
i=++i*10;
i=--i*10;
}
void show()
{
cout << i << endl;
}
};
void main()
{
A a1;
clrscr();
a1.i=5;
cout << a1.i << endl;
++a1;
a1.show();
getch();
}

Output:
5
590

 

Leave a Reply