As long as there can be no implicit conversions, both are equally good;
it's more a matter of taste. If there can implicit conversions to
Complex
(which in this case seems likely), then with the first form,
implicit conversions will only work on the second argument, e.g.:
Complex c;
Complex d;
d = c + 1.0; // Works in both cases...
d = 1.0 + c; // Only works if operator+ is free function
In such cases, the free function is by far the preferred solution; many
people prefer it systematically, for reasons of orthogonality.
In many such cases, in fact, the free function operator+
will be
implemented in terms of operator+=
(which will be a member):
Complex
operator+( Complex const& lhs, Complex const& rhs )
{
Complex results( lhs );
results += rhs;
return results;
}
In fact, it's fairly straightforward to provide a template base class
which provides all of these operators automatically. (In this case,
they're declared friend
, in order to define them in line in the
template base class.)