Peter Dimov wrote:
Cheenu Srinivasan wrote:
Duane Murphy wrote:
The return type of boost::bind is fairly indeterminate. In order to call a bound function at a later time, look at boost::function. It does a nice job of holding on to a function that uses boost::bind.
I looked at "Using bind with Boost.Function" in the boost::function docs. Mimicing that, for my example, I tried:
boost::function
bound_func = boost::bind(f, _1, 1.234); int i = 99; cout << bound_func(i) << endl; but it throws a bad_function_call exception when bound_func(i) is invoked. How do I use boost::function for this situation?
Works for me; it's probably a compiler bug. Which compiler are you using?
Try
boost::function
bound_func( boost::bind(f, _1, 1.234) ); instead.
With MSVC 7.1. the exception is thrown with both 'bound_func = bind(...)' and 'bound_func(bind(...))'. But I tried it with g++/solaris and it works. So it does look like a bug with the MS compiler. Thanks.