fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class three_d {
  5. int x, y, z;
  6. public:
  7. three_d(int a, int b, int c) {x=a; y=b, z=c; }
  8. three_d operator+(const three_d& op2) const;
  9. friend ostream &operator<<(ostream &stream, const three_d &obj);
  10. };
  11. ostream &operator<< (ostream &stream, const three_d &obj)
  12. {
  13. stream << obj.x << ", ";
  14. stream << obj.y << ", ";
  15. stream << obj.z << endl;
  16. return stream;
  17. }
  18. three_d three_d::operator+ (const three_d &op2) const
  19. {
  20. return three_d(x + op2.x, y + op2.y, z + op2.z);
  21. }
  22.  
  23. int main()
  24. {
  25. three_d a(1, 2, 3), b(2, 3, 4), c(3, 4, 5);
  26. cout << a+b+c << endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
6, 9, 12