On 12 avr, 05:25, "Alf P. Steinbach /Usenet" <alf.p.steinbach
+use...@gmail.com> wrote:
> * Ruben Safir, on 12.04.2011 04:43:
>
> > On Tue, 12 Apr 2011 04:01:25 +0200, Alf P. Steinbach /Usenet wrote:
>
> >> * Ruben Safir, on 12.04.2011 03:59:
> >>> On Tue, 12 Apr 2011 02:29:10 +0200, Alf P. Steinbach /Usenet wrote:
>
> >>>> * Ruben Safir, on 12.04.2011 01:39:
> >>>>> as I understand things, the operator<<() needs to be external as to
> >>>>> the class and then declared as a friend of the class. *I'm not sure
> >>>>> if I understand why that is the case.
>
> >>> what?? *operator<<() can be a normal class member?
>
> >> Yes.
>
>
> >http://en.wikibooks.org/wiki/C++_Pro...Operator_Overl...
>
> > Of special mention are the shift operators,<< *and>>. These have beenoverloaded in the standard library for interaction with streams. When overloading these operators to work with streams the rules below should be followed:
>
> > * * 1. overload<< *and>> *as friends (so that it can access theprivate variables with the stream be passed in by references
> > * * 2. (input/output modifies the stream, and copying is not allowed)
> > * * 3. the operator should return a reference to the stream it receives (to allow chaining, cout<< *3<< *4<< *5)
>
> Your question seems to be missing.
Because IMHO your answer was misleading.
Tes, In the general case, operator<<() - i.e. shift operator - can be
defined as a member function.
AFAIS Ruben Safier was asking about operator<<() for stream output. In
this case, yes, he must defined it as a free function (friend or not).
--
Michael