
12 Apr
2004
12 Apr
'04
3:36 p.m.
Thorsten Ottosen wrote:
"Peter Dimov" <pdimov@mmltd.net> wrote in message news:001501c42095$eb0425b0$1d00a8c0@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.