Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6.  
  7. struct Test {
  8.     int a;
  9.     int b;
  10.     int c;
  11.     Test() : a(0), b(0), c(0) {}
  12.     Test operator+(const Test &rhs) const;
  13. };
  14.  
  15. Test Test::operator+(const Test &rhs) const
  16. {
  17.     Test res, nores;
  18.     // cannot print the content of res (uninitialized), but nores is right.
  19.     res.a = a + rhs.a;
  20.     res.b = b + rhs.b;
  21.     res.c = c + rhs.c;
  22.     return res;
  23. }
  24. ostream &operator<<(ostream &out, const Test &a)
  25. {
  26.     out << a.a << ' ' << a.b << ' ' << a.c << endl;
  27. }
  28.  
  29. int main()
  30. {
  31.     Test p1, p2;
  32.     cout << p1 + p2 << endl;
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement