Using a shared_ptr in a boost::function definition?

Hi Folks,
I can't quite figure out how to do this correctly (*note* the types ending
in Ptr are typedef'd boost::shared_ptr types)
I have a function like so: -
void setCompleteFunction(boost::function< void (int errorCode, const string
&data, HeaderMapPtr headers) > f);
I try to bind to it: -
wc->setCompleteFunction(boost::bind(&NetworkEventHandler::receiveSkinDownloadResult,
this, _1, _2, _3, wc,myFile, filename.str(), carId, crc, networkPlayerId));
I get quite a few errors indicating that it can't match to this pattern,
this is the most sensible message: -
error C2784:
'boost::_bi::bind_t

void setCompleteFunction(boost::function< void (int errorCode, const string &data, HeaderMapPtr headers) > f);
I try to bind to it: -
wc->setCompleteFunction(boost::bind(&NetworkEventHandler::receiveSkinDownloadResult, this, _1, _2, _3, wc,myFile, filename.str(), carId, crc, networkPlayerId));
The boost::function you have to pass as a parameter gets 3 parameters. If you want to "delay" passing all the 3 params, you create the following binder: bind(&NetworkEventHandler::receiveSkinDownloadResult, this, _1, _2, _3); If you want to bind some of params, you can do it like this: bind(&NetworkEventHandler::receiveSkinDownloadResult, this, knownErrorCore, _1, _2);

Igor R wrote:
void setCompleteFunction(boost::function< void (int errorCode, const string &data, HeaderMapPtr headers) > f);
I try to bind to it: -
wc->setCompleteFunction(boost::bind(&NetworkEventHandler::receiveSkinDownloadResult, this, _1, _2, _3, wc,myFile, filename.str(), carId, crc, networkPlayerId));
The boost::function you have to pass as a parameter gets 3 parameters. If you want to "delay" passing all the 3 params, you create the following binder: bind(&NetworkEventHandler::receiveSkinDownloadResult, this, _1, _2, _3); If you want to bind some of params, you can do it like this: bind(&NetworkEventHandler::receiveSkinDownloadResult, this, knownErrorCore, _1, _2);
Hi Igor, You can supply more parameters than the defined function as long as you explicitly set the rest of the parameters (so when the function with 3 parameters is called it'll supply the other parameters too to the "receiving" function). I think Peter has the answer with his reply, I am using too many parameters (there is a limit it seems). I'll try to bunch them together in a structure perhaps. Thanks for your help All the best, Ash -- View this message in context: http://www.nabble.com/Using-a-shared_ptr-in-a-boost%3A%3Afunction-definition... Sent from the Boost - Users mailing list archive at Nabble.com.

You can supply more parameters than the defined function as long as you explicitly set the rest of the parameters (so when the function with 3 parameters is called it'll supply the other parameters too to the "receiving" function).
Of course, you're right. The parameters will be stored inside the binder, but how can you access/use these extra parameters later?

Ashley McConnell:
Hi Folks,
I can't quite figure out how to do this correctly (*note* the types ending in Ptr are typedef'd boost::shared_ptr types)
I have a function like so: -
void setCompleteFunction(boost::function< void (int errorCode, const string &data, HeaderMapPtr headers) > f);
I try to bind to it: -
wc->setCompleteFunction(boost::bind(&NetworkEventHandler::receiveSkinDownloadResult, this, _1, _2, _3, wc,myFile, filename.str(), carId, crc, networkPlayerId));
I get quite a few errors indicating that it can't match to this pattern,
... You are exceeding bind's limit of 9 arguments.

Peter Dimov-5 wrote:
...
You are exceeding bind's limit of 9 arguments.
Thanks, I will try to group them together more sensibly when I get a chance (I'm upgrading to VS2008 and switching a few lib versions at the minute so things are compiling) Thanks again All the best, Ash -- View this message in context: http://www.nabble.com/Using-a-shared_ptr-in-a-boost%3A%3Afunction-definition... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (3)
-
Ashley McConnell
-
Igor R
-
Peter Dimov