Boost logo

Boost Users :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2006-03-29 18:06:47


On 3/29/06, Nico Galoppo <nico_at_[hidden]> wrote:
> Hi,
>
> what kind of object does boost::bind return when binding to a class member
> variable ? (as opposed to a member method). Is it a function object too?
>
> More in particular, I would like to write a generic free function that applies
> an operation on a particular member variable, passed in with boost::bind.
> Something like this:
>
> struct A {
> int value;
> };
>
> void f(bind_return_type& membervar)
> {
> membervar = 3;
> }
>
> A a;
> f(bind(&A::value, a));
>
>
> Thanks.
>
> --nico
>

Couldn't you just do

void f(int& membervar)
{
  membervar = 3;
}

A a;
f(a.value);

?
To get back to bind return types - they're not simple. Your best bet
is to use boost::function to hold the result of boost::bind if you
want to keep it around. Just make sure any variables involved are
still alive when the function is eventually invoked.

Stuart Dootson


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