Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind with references
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-30 21:57:53


AMDG

Zachary Turner wrote:
> I have a function defined as
>
> template<typename T>
> void foo(const T& x);
>
> and then I use boost::bind(foo, x);
>
> However, once the code is inside the body of foo, the addresses of x
> inside foo and the addresses of x when I called bind are different.
> So somehow a copy is being made. I can get around it by using
> boost::ref(), but is there a technical reason why it doesn't "just
> work" and pass it by reference

Capturing by reference is more dangerous because
it can leave dangling references.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net