[Please do not mail me a copy of your followup]
Doug Mika <
doug...@gmail.com> spake the secret code
<
e90d32f4-65f1-4a3b...@googlegroups.com> thusly:
>My first question was indeed, what is ->, that's clear now.
>But the question that remains is why would we overload the + operator on
>a class C, for example, outside of the class? Why not include operator+
>inside our class C definition?
Prefer small, simple classes over large ones.
If you force everything to be a member function, even those functions
that aren't *required* to be a member function, then you end up with
the rather large bloated class that is std::string. The rule of thumb
is: if you can implement something as a free function (i.e. not a
member function) using the public interface of a class then prefer that
over a member function.
This goes hand-in-hand with the advice for namespaces -- the only thing
not in a namespace is your implementation of main(). You put the class
and its associated free functions all inside a namespace and then they
don't get in the way of other free functions for other classes and ADL
guarantees that the right operator+ is selected when used with that
class.