fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Vector {
  5. public:
  6. int x;
  7. int y;
  8. int z;
  9.  
  10. Vector operator+(const Vector& other) {
  11. Vector c;
  12. c.x = this->x + other.x;
  13. c.y = this->y + other.y;
  14. c.z = this->z + other.z;
  15. return c;
  16. }
  17. };
  18.  
  19. int main() {
  20. Vector x, y, z;
  21.  
  22. x.x = 1;
  23. x.y = 2;
  24. x.z = 3;
  25.  
  26. y.x = 4;
  27. y.y = 5;
  28. y.z = 6;
  29.  
  30. z = x + y;
  31.  
  32. cout << x.x << " " << x.y << " " << x.z << endl;
  33. cout << y.x << " " << y.y << " " << y.z << endl;
  34. cout << z.x << " " << z.y << " " << z.z << endl;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 4288KB
stdin
Standard input is empty
stdout
1 2 3
4 5 6
5 7 9