bhupixb

Operator overloading using Template

Sep 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. template < class T , class TT>
  4. class my{
  5. TT a; T b, c;
  6. public:
  7.  
  8. my operator-(my );
  9. friend ostream& operator<<(ostream &out, my &x){
  10. out << x.a << ' ' << x.b << ' ' << x.c;
  11. return out;
  12. }
  13. friend istream& operator>>(istream &in, my &x){// &x is must find out the reason why
  14. in >> x.a >> x.b >> x.c;
  15. return in;
  16. }
  17.  
  18. };
  19. template < class aa , class bb>
  20. my < aa, bb > my < aa, bb > :: operator-(my x){
  21. my temp;
  22.  
  23. temp.a = a - x.a;
  24. temp.b = b - x.b;
  25. temp.c = c - x.c;
  26. return temp;
  27. }
  28.  
  29. int main(int argc, char const *argv[]){
  30. my < int, float > ob,ob2, ob3;
  31. cin >> ob >> ob2;
  32. ob3 = ob - ob2;
  33. cout << ob3 << '\n';
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment