[bind] Problem with 1.33.1, g++ 3.3.3

I'm trying to compile this little program:
#include

David Greene wrote:
I'm trying to compile this little program:
#include
#include <iostream>
namespace tester { class Test { public: void do_test(void) { std::cout << "Done!" << std::endl; }; }; };
int main(void) { tester::Test x;
bind(&tester::Test::do_test, &x, _1)();
http://www.boost.org/libs/bind/bind.html#err_num_args tester::Test::do_test takes one argument (the implicit 'this'), you are passing two, &x and _1 (the first input argument). In addition, although this is not relevant for this particular case, http://www.boost.org/libs/bind/bind.html#err_arg_access you are trying to access the first argument with _1 but no such argument exists since you are calling the result of bind with (), i.e. zero arguments. Summary: bind(&tester::Test::do_test, &x)(); or maybe bind(&tester::Test::do_test, _1)( x );
return(0); }

Peter Dimov wrote:
David Greene wrote:
I'm trying to compile this little program:
#include
#include <iostream>
namespace tester { class Test { public: void do_test(void) { std::cout << "Done!" << std::endl; }; }; };
int main(void) { tester::Test x;
bind(&tester::Test::do_test, &x, _1)();
http://www.boost.org/libs/bind/bind.html#err_num_args
tester::Test::do_test takes one argument (the implicit 'this'), you are passing two, &x and _1 (the first input argument).
Aha! Ok, so it was a fundamental misunderstanding of the bind mechanism itself. For some reason I had it in my head that _1 indicated which argument that &x should be bound to. -Dave

David Greene wrote:
int main(void) { tester::Test x;
bind(&tester::Test::do_test, &x, _1)();
return(0); }
Your syntax is wrong. You only use the _n placeholders for arguments actually passed to the function. Since you use _1, the resulting bind object expects one parameter, which you don't supply. The correct bind expression is bind(&tester::Test::do_test, &x); and you call it thus bind(&tester::Test::do_test, &x)(); Sebastian Redl
participants (3)
-
David Greene
-
Peter Dimov
-
Sebastian Redl