Binary Operator OverLoading

 #include<iostream>;

using namespace std;

class ABC {
public:
int a, b;//10 20
ABC(int x,int y):a(x),b(y) {

}

ABC operator +(ABC & abc) {
return ABC(a + abc.a, b + abc.b);
}

};


int main() {
ABC a_obj(10,20), b_obj(100,200);//c_obj a=110,b=220;
//c=a + b;
ABC c_obj = a_obj + b_obj;

cout << "A=" << c_obj.a << " B=" << c_obj.b;

return 0;
}

Comments

Popular posts from this blog

Dynamic Memory2

Template

MultiLevel