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

178

Advertisements