|
Boost Users : |
Subject: Re: [Boost-users] Using Boost::Bind
From: David McCallum (dmccallum9_at_[hidden])
Date: 2011-06-29 12:28:25
I should clarify, this is what I want to achieve:
boost::function<void (DBuffer&)> singleHandler;
void addHandler(boost::function<void (DBuffer&)> newHandler)
{
singleHandler = newHandler;
}
The problem is that I don't know how to call boost::bind with a
DBuffer parameter, where DBuffer is one of my own 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;
>
> hostResolver->async_resolve( *nameQuery,
> boost::bind(&DClient::resolveHandler, this,
> boost::asio::placeholders::error,
> 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.
If I understand you correctly, then in the following code:
void DClient::resolveHandler(int param)
{
....
}
boost::function<void (int)> functionPtr;
int tempInt = 12;
myHandler = boost::bind(&DClient::resolveHandler, this, tempInt);
myHandler(67);
The final line will call resolveHandler with a parameter of 12, rather
than 67? Surely that can't be right?
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