fork download
  1. #include <iostream>
  2.  
  3. struct Point {
  4. int x_, y_;
  5. Point(int x, int y) : x_(x), y_(y) {}
  6. };
  7.  
  8. struct Vector {
  9. int x_, y_;
  10. Vector(int x, int y) : x_(x), y_(y) {}
  11. };
  12.  
  13. std::ostream& operator<<(std::ostream& os, Point const& p)
  14. {
  15. return os << '(' << p.x_ << ',' << p.y_ << ')';
  16. }
  17.  
  18. std::ostream& operator<<(std::ostream& os, Vector const& v)
  19. {
  20. return os << '(' << v.x_ << ',' << v.y_ << ')';
  21. }
  22.  
  23. int main() {
  24. Point p(3, 3);
  25. Vector v(2, -4);
  26. Point p2(p.x_ - v.x_, p.y_ - v.y_);
  27. std::cout << "Point p: " << p << '\n';
  28. std::cout << "Vector v: " << v << '\n';
  29. std::cout << "Point p2: " << p2 << '\n';
  30. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Point p:  (3,3)
Vector v: (2,-4)
Point p2: (1,7)