Add operator<< for Point class in ex03
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 24 Oct 2024 13:14:15 +0000 (15:14 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 24 Oct 2024 13:14:15 +0000 (15:14 +0200)
ex03/Point.cpp
ex03/Point.h

index e3e6c8c662a2da791cbfad6bab6e7770596c297c..e1d3e78f5a32a9173e3b643c151f2fe6271106e7 100644 (file)
@@ -43,3 +43,14 @@ int  Point::halfplane_sgn(Point a, Point b) const
        else
                return (0);
 }
+
+void   Point::print(std::ostream &ostream) const
+{
+       ostream << '(' << x << ", " << y << ')';
+}
+
+std::ostream   &operator<<(std::ostream &ostream, const Point &point)
+{
+       point.print(ostream);
+       return (ostream);
+}
index b6e92177ee1fad050c6c62886cd4b4570b50bece..0118baa7ec3ae66428358ac9fc4c6a408ff833c0 100644 (file)
@@ -17,9 +17,12 @@ class Point
 
                Point   &operator=(const Point &other);
 
-               int     halfplane_sgn(Point a, Point b) const;
+               int             halfplane_sgn(Point a, Point b) const;
+               void    print(std::ostream &ostream) const;
 };
 
+std::ostream   &operator<<(std::ostream &ostream, const Point &num);
+
 bool   bsp(const Point a, const Point b, const Point c, const Point point);
 
 #endif // POINT_H