Boost Users :
Subject: Re: [Boost-users] Using Boost::Bind
From: Michael Caisse (boost_at_[hidden])
Date: 2011-06-28 19:10:59
On 06/28/2011 03:38 PM, Igor R wrote:
>> But what if I want to use a primitive variable, or a pointer to one of
>> my classes? Do I need to make a placeholder for each type of parameter
>> I want to use?
> No, you can use bind placeholders _1, _2, _3 etc.
That wont work. Those are placeholders and the caller doesn't have the
caller "primitive variable, or a pointer to one of my classes".
You will want to learn a bit more about Boost.Bind. You can bind your
pointer or variable at the bind call. Parameters at the time of bind are
copied by value. If you need a reference use the boost::ref wrapper.
Expanding your example:
void DClient::resolveHandler( const boost::system::error_code& error,
int value );
int special_number = 42;
special_number ) );
In the above, when the handler is invoked it will pass the error value
(via the placeholder) and the value of special_number during the bind...
which is 42.
You should also take a look at using shared_from_this with async
handlers to make lifetime management easier.
More tips can be found in my BoostCon'10 Asio talk:
-- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
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