Advertisement
TechOPGOHIL

Untitled

Dec 3rd, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. //Write Binary Operator Overloding with Example
  2. #include<iostream.h>
  3. #include<conio.h>
  4. class demo
  5. {
  6.     int a,b;
  7.     public:
  8.     demo (int x, int y)
  9.     {
  10.         a=x;
  11.         b=y;
  12.     }
  13.     demo()
  14.     {
  15.     }
  16.     void display()
  17.     {
  18.         cout<<"\nA = "<<a<<endl;
  19.         cout<<"\nB = "<<b<<endl;
  20.     }
  21.     demo operator +(demo obj1)
  22.     {
  23.         demo tmp;
  24.         tmp.a=a+obj1.a;
  25.         tmp.b=b+obj1.b;
  26.         return tmp;
  27.     }
  28.  
  29. };
  30. void main()
  31. {
  32.     clrscr();
  33.     demo o(10,20);
  34.     demo o2(40,80);
  35.     demo o3;
  36.     o3=o+o2;
  37.     o3.display();
  38.     getch();
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement