Boost logo

Boost Users :

Subject: Re: [Boost-users] Using Boost::Bind
From: Igor R (boost.lists_at_[hidden])
Date: 2011-06-29 12:45:00


> void DClient::resolveHandler(int param)
> {
>   ....
> }
>
> boost::function<void (int)> functionPtr;
> int tempInt = 12;
>
> functionPtr = boost::bind(&DClient::resolveHandler, this, tempInt);
> functionPtr(67);
>
> The final line will call resolveHandler with a parameter of 12, rather
> than 67? Surely that can't be right?

Correct, the function will be called with 12. You can ensure this with
this small program:

#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>

void resolveHandler(int param)
{
  std::cout << param << std::endl;
}

boost::function<void (int)> functionPtr;
int tempInt = 12;

int main()
{
  functionPtr = boost::bind(&resolveHandler, tempInt);
  functionPtr(67);
}


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