Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3445

Re: templated operator()<<

From "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: templated operator()<<
Date 2011-04-12 05:25 +0200
Organization A noiseless patient Spider
Message-ID <io0gn3$3ie$1@dont-email.me> (permalink)
References <io03f9$qsv$1@reader1.panix.com> <io06co$fgm$1@dont-email.me> <io0bl5$9hr$1@reader1.panix.com> <io0bpn$dph$2@dont-email.me> <io0e7q$qsv$3@reader1.panix.com>

Show all headers | View raw


* 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.
>>
>>
>> Cheers&  hth.,
>>
>> - Alf
> http://en.wikibooks.org/wiki/C++_Programming/Operators/Operator_Overloading#Operators_as_member_functions
>
>
> Of special mention are the shift operators,<<  and>>. These have been overloaded 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 the private 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.


Cheers & hth.,

- Alf

-- 
blog at <url: http://alfps.wordpress.com>

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

templated operator()<< Ruben Safir <ruben@mrbrklyn.com> - 2011-04-11 23:39 +0000
  Re: templated operator()<< LR <lruss@superlink.net> - 2011-04-11 20:07 -0400
  Re: templated operator()<< "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-12 02:29 +0200
    Re: templated operator()<< Ruben Safir <ruben@mrbrklyn.com> - 2011-04-12 01:59 +0000
      Re: templated operator()<< "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-12 04:01 +0200
        Re: templated operator()<< Ruben Safir <ruben@mrbrklyn.com> - 2011-04-12 02:37 +0000
        Re: templated operator()<< Ruben Safir <ruben@mrbrklyn.com> - 2011-04-12 02:43 +0000
          Re: templated operator()<< "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-12 05:25 +0200
            Re: templated operator()<< Michael Doubez <michael.doubez@free.fr> - 2011-04-12 00:17 -0700
      Re: templated operator()<< Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-12 08:23 +0200

csiph-web