fork download
  1. #include <iostream>
  2.  
  3. class move
  4. {
  5. private:
  6. double x, y;
  7.  
  8. public:
  9. move(double x = .0, double y = .0) : x(x), y(y)
  10. {
  11. }
  12.  
  13. void show() const
  14. {
  15. std::cout << "x: " << x << ", y: " << y << std::endl;
  16. }
  17.  
  18. move add(const move& m) const
  19. {
  20. return move(m.x + x, m.y + y);
  21. }
  22.  
  23. void reset(double a = .0, double b = .0)
  24. {
  25. x = a;
  26. y = b;
  27. }
  28. };
  29.  
  30. int main() {
  31. move m(2.5, 2.5);
  32. move new_move = m.add(move(2.5, 2.5));
  33. new_move.show();
  34. return 0;
  35. }
Success #stdin #stdout 0s 4408KB
stdin
Standard input is empty
stdout
x: 5, y: 5