From 6824a51d7015b1a21034056d28b073bfb7047693 Mon Sep 17 00:00:00 2001 From: Daniel Warner Date: Sat, 9 Apr 2011 19:57:58 +0100 Subject: [PATCH] Formatting and check not assigning to self in operator= --- Julian.cpp | 6 +++++- Julian.h | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Julian.cpp b/Julian.cpp index e59175e..28db393 100644 --- a/Julian.cpp +++ b/Julian.cpp @@ -111,11 +111,15 @@ bool Julian::operator<=(const Julian &date) const { * assignment */ Julian& Julian::operator=(const Julian& b) { - date_ = b.date_; + + if (this != &b) { + date_ = b.date_; + } return (*this); } Julian& Julian::operator=(const double b) { + date_ = b; return (*this); } diff --git a/Julian.h b/Julian.h index 6d363ab..59b0269 100644 --- a/Julian.h +++ b/Julian.h @@ -24,10 +24,10 @@ public: bool operator>=(const Julian &date) const; bool operator<=(const Julian &date) const; - Julian& operator=(const Julian& b); -Julian& operator=(const double b); -Julian operator+(const Timespan& b) const; -Julian operator-(const Timespan& b) const; + Julian & operator=(const Julian& b); + Julian & operator=(const double b); + Julian operator+(const Timespan& b) const; + Julian operator-(const Timespan& b) const; ~Julian() { };