Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write Binary Operator Overloding with Example
- #include<iostream.h>
- #include<conio.h>
- class demo
- {
- int a,b;
- public:
- demo (int x, int y)
- {
- a=x;
- b=y;
- }
- demo()
- {
- }
- void display()
- {
- cout<<"\nA = "<<a<<endl;
- cout<<"\nB = "<<b<<endl;
- }
- demo operator +(demo obj1)
- {
- demo tmp;
- tmp.a=a+obj1.a;
- tmp.b=b+obj1.b;
- return tmp;
- }
- };
- void main()
- {
- clrscr();
- demo o(10,20);
- demo o2(40,80);
- demo o3;
- o3=o+o2;
- o3.display();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement