Skip to main content

Operator Function in C++

 


#include<bits/stdc++.h>

using namespace std;

class sum{
    int a, b;
    public:
    void getdata(int x, int y){
        a=-x;
        b=-y;

    }
    void display(){
        cout<<endl<<" "<<a<<"  "<<b<<endl;
    }

    sum operator +(sum c){
        sum temp;
        temp.a=a+c.a;
        temp.b=b+c.b;
        return (temp);
    }
   
};
int main()
{      
    sum c1,c2,c3,c4;
    c1.getdata(2,4);
    c2.getdata(4,2);
    c3=c2+c1;
    c3.display();
   
   
   
    return 0;
}

Comments