The principle of least surprise suggests that your overload should behave more or less like built-in operators. The usual solution here is not to implement operator+ at all, but to implement:
D& operator+=( D const& rhs );
as a member, and then get something like:
template<typename T> class ArithmeticOperators { friend T operator+( T const& lhs, T const& rhs ) { T result( lhs ); result += rhs; return result; }
Thus, you do not need to rewrite the same thing every time you define a class that overloads arithmetic operators, and you are guaranteed that the semantics of + and += correspond.
(The friend in the above just allows you to put the function, along with its implementation, in the class itself, where ADL finds it.)
source share