From 47f0263ca3c8c9fdff230995335f45ec87cd0282 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Fri, 3 Jul 2015 22:21:02 +0300 Subject: [PATCH] Add unary minus operator for Point --- SDL2pp/Point.cc | 4 ++++ SDL2pp/Point.hh | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 5ed4146..1a24745 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -66,6 +66,10 @@ Point& Point::SetY(int ny) { return *this; } +Point Point::operator-() const { + return Point(-x, -y); +} + Point Point::operator+(const Point& other) const { return Point(x + other.x, y + other.y); } diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index bae5ba6..bce691f 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -156,6 +156,14 @@ public: //////////////////////////////////////////////////////////// Point& SetY(int ny); + //////////////////////////////////////////////////////////// + /// \brief Get point's memberwise negation + /// + /// \returns New Point representing memberwise negation + /// + //////////////////////////////////////////////////////////// + Point operator-() const; + //////////////////////////////////////////////////////////// /// \brief Get point's memberwise addition with another point ///