Note: – If operator function as member function then in the case with postfix increment or decrement. We must specify (int) keyword inside the parenthesis of operator function.

#include<iostream.h>
#include<conio.h>
class increment
{
private:
                int a,b;
public:
                increment(int p,int q)
                                {
                                a=p;
                                b=q;
                                }
                void display()
                                {
                                cout<<"A = "<<a<<"\tB = "<<b<<endl;
                                }
                void operator ++ (int);
};
void increment::operator ++ (int)
{
                a++;
                b++;
}
void main()
{
                clrscr();
                increment x(5,3);
                x++;
                cout<<"After Operator Overloading \n";
                x.display();
                getch();
}

182.PNG

Advertisements