From 006d2de34a604fc07e8d0fcc16fd99ef42fb8558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Mon, 12 Feb 2018 01:11:23 +0100 Subject: [PATCH] Stream operator for Ball --- Ball.cpp | 9 +++++++++ Ball.hpp | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Ball.cpp b/Ball.cpp index 0ded1f3..a2e3705 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -1,4 +1,5 @@ #include "Ball.hpp" +#include #include Ball::Ball(Point& _center, double _v_x, double _p, double _q) : @@ -52,3 +53,11 @@ void Ball::update_pos(double dt) { } _compute_pos(dt); } + +std::ostream& operator<< (std::ostream &out, Ball const& data) { + Point center = data.getCenter(); + out << center.x << ':'; + out << center.y << ':'; + out << center.z << '\n'; + return out; +} diff --git a/Ball.hpp b/Ball.hpp index 383979d..39a3dd0 100644 --- a/Ball.hpp +++ b/Ball.hpp @@ -9,7 +9,7 @@ * each bounce, which is a reasonable assumption since it is the same for the * vertical bounces. **/ - +#pragma once #include #include "spheroid.hpp" @@ -33,4 +33,7 @@ class Ball { public: Ball(Point& _center, double _v_x, double p, double q); void update_pos(double dt); + Point getCenter() const {return Center;} }; + +std::ostream& operator << (std::ostream &out, Ball const& data);