Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- struct Test {
- int a;
- int b;
- int c;
- Test() : a(0), b(0), c(0) {}
- Test operator+(const Test &rhs) const;
- };
- Test Test::operator+(const Test &rhs) const
- {
- Test res, nores;
- // cannot print the content of res (uninitialized), but nores is right.
- res.a = a + rhs.a;
- res.b = b + rhs.b;
- res.c = c + rhs.c;
- return res;
- }
- ostream &operator<<(ostream &out, const Test &a)
- {
- out << a.a << ' ' << a.b << ' ' << a.c << endl;
- }
- int main()
- {
- Test p1, p2;
- cout << p1 + p2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement