|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-04-12 10:36:16
Thorsten Ottosen wrote:
> "Peter Dimov" <pdimov_at_[hidden]> wrote in message
> news:001501c42095$eb0425b0$1d00a8c0_at_pdimov2...
>> Thorsten Ottosen wrote:
>>>
>>> My point is that if the prototype was
>>>
>>> void square( int& );
>>>
>>> then
>>>
>>> function< void(void) > f( int x )
>>> {
>>> return bind( square, x*5 );
>>> }
>>>
>>> should not compile.
>>
>> Why should it not compile?
>
> consider instead
>
> void write_to( string& s )
> {
> s += " foo";
> }
>
> string s = "bar";
> bind( write_to, s )();
> cout << s; // won't print "bar foo"
That's how bind works. All arguments in "bind(write_to, s)" are copied,
including 'write_to'. If you make 'write_to' a stateful function object,
"bind(write_to, s)()" won't update 'write_to' either.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk