#include<iostream.h>
#include<conio.h>
class subtraction
{
private:
                int a,b;
public:
                subtraction()
                                {
                                }
                subtraction(int p,int q)
                                {
                                a=p;
                                b=q;
                                }
                void display()
                                {
                                cout<<"A = "<<a<<"\tB = "<<b<<endl;
                                }
                friend subtraction operator - (subtraction obj1,subtraction obj2);


;
subtraction operator - (subtraction obj1,subtraction obj2)
{
                subtraction s;
                s.a=obj1.a-obj2.a;
                s.b=obj1.b-obj2.b;
                return s;
}
void main()
{
                clrscr();
                subtraction x(5,3),y(8,6),z;
                z=x-y;    //Operator overloading
                cout<<"After Operator Overloading \n";
                z.display();
                getch();
}

177

Advertisements