From f4351c0c1118f7e5a35f10d0656091c05ae7d5b0 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 8 Nov 2010 18:27:58 +0100 Subject: [PATCH] check for self assignement in copy operator of eoDualFitness --- eo/src/eoDualFitness.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/eo/src/eoDualFitness.h b/eo/src/eoDualFitness.h index 0ab99413f..3fb9c0a37 100644 --- a/eo/src/eoDualFitness.h +++ b/eo/src/eoDualFitness.h @@ -104,14 +104,6 @@ public: return _is_feasible; } - //! Copy operator - eoDualFitness& operator=(const eoDualFitness& other) - { - _value = other._value; - _is_feasible = other._is_feasible; - return *this; - } - //! Copy operator from a std::pair eoDualFitness& operator=(const std::pair& v) { @@ -119,6 +111,18 @@ public: _is_feasible = v.second; return *this; } + + //! Copy operator from another eoDualFitness + template + eoDualFitness & operator=(const eoDualFitness& other ) + { + if (this != &other) { + this->_value = other._value; + this->_is_feasible = other._is_feasible; + } + return *this; + } + //! Comparison that separate feasible individuals from unfeasible ones. Feasible are always better /*! @@ -155,6 +159,7 @@ public: //! Greater or equal: if the other is not greater than me bool operator>=(const eoDualFitness& other ) const { return !(*this < other); } + public: //! Add a given fitness to the current one