[bind][function] Newbie finds errors, but in Boost or between chair and keyboard?
Greetings,
I'm a newbie, at least to Boost, and I have been playing around with it to get
familiar with it, and to improve my c++ skills. :)
I've run into two problems with boost::bind (and I suspect there is a connection
with boost::function). The two programs at the bottom of this message
demonstrate these problems.
Can anybody shed a light on this? Are these errors in Boost, or did I miss
something in the documentation? Should I ask on another mailing list? Or should
I file a bug report?
Platform: linux-x86
Compiler: GNU C++ version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
STL : GNU libstdc++ version 20061115
Boost : 1.35.0
Regards,
Jeroen.
------------------------------------------------------------------------
#include
AMDG Jeroen N.Witmond wrote:
int main(void) { boost::function1
mything; mything = boost::bind(doit, 3);
// The statement below results in error:
<snip> return mything() ? 0 : 1; }
boost::function1
// But replacing one_arg_f by its value fails to compile: // /usr/include/boost/bind.hpp:413: error: invalid use of void // expression boost::bind(&anything::operator(), &something, _1, _2, boost::bind(&anything::one_arg, &something, _1, 80235)) (12345, 67890);
Nested binds are treated specially. The above tries to invoke: something(12345, 67890, something.one_arg(12345, 80235)); Try using protect on the inner bind: boost::protect(boost::bind(&anything::one_arg, &something, _1, 80235))) In Christ, Steven Watanabe
Steven Watanabe
boost::function1
is a unary function object. You can't call it with no arguments. What you meant is probably boost::function0<bool>.
Just goes to show that I'm also a newbie in interpreting this kind of compiler error messages. :) The code I posted was an attempt at a testcase for the actual problem I had. Your answer pointed me in the right direction to solve this.
// But replacing one_arg_f by its value fails to compile: // /usr/include/boost/bind.hpp:413: error: invalid use of void // expression boost::bind(&anything::operator(), &something, _1, _2, boost::bind(&anything::one_arg, &something, _1, 80235)) (12345, 67890);
Nested binds are treated specially. The above tries to invoke: something(12345, 67890, something.one_arg(12345, 80235));
Try using protect on the inner bind: boost::protect(boost::bind(&anything::one_arg, &something, _1, 80235)))
I'll keep it in mind. Thanks for your quick and helpful reply. Jeroen.
participants (2)
-
Jeroen N. Witmond
-
Steven Watanabe