[bind] Problem with 1.33.1, g++ 3.3.3

I'm trying to compile this little program: #include <boost/bind.hpp> #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)(); return(0); } But I end up with this error (full error trace below): /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind.hpp:63: error: ` void (tester::Test::*)()' is not a class, struct, or union type It looks like somewhere along the way the wrong template specialization is chosen for result type deduction. Am I doing something wrong or is this a known problem? I tried lambda's bind but that also gives an error. It's a different error but I believe it amounts to the same problem. Thanks! -Dave ------------------------ bind.cc:16: instantiated from here /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind.hpp:63: error: ` void (tester::Test::*)()' is not a class, struct, or union type /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind/bind_template.hpp: In instantiation of `boost::_bi::bind_t<boost::_bi::unspecified, void (tester::Test::*)(), boost::_bi::list2<boost::_bi::value<tester::Test*>, boost::arg<1> > >': /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind.hpp:1409: instantiated from `boost::_bi::bind_t<boost::_bi::unspecified, F, typename boost::_bi::list_av_2<A1, A2>::type> boost::bind(F, A1, A2) [with F = void (tester::Test::*)(), A1 = tester::Test*, A2 = boost::arg<1>]' bind.cc:16: instantiated from here /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind/bind_template.hpp:15: error: no type named `type' in `struct boost::_bi::result_traits<boost::_bi::unspecified, void (tester::Test::*)()> ' /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind/bind_template.hpp:18: error: no type named `type' in `struct boost::_bi::result_traits<boost::_bi::unspecified, void (tester::Test::*)()> ' /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind/bind_template.hpp:24: error: no type named `type' in `struct boost::_bi::result_traits<boost::_bi::unspecified, void (tester::Test::*)()> ' /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind/bind_template.hpp:30: error: no type named `type' in `struct boost::_bi::result_traits<boost::_bi::unspecified, void (tester::Test::*)()> ' /tools/i686-pc-linux-gnu/include/boost-1_33_1/boost/bind/bind_template.hpp:30: confused by earlier errors, bailing out make: *** [bind.o] Error 1 Compilation exited abnormally with code 2 at Mon Jan 9 17:08:20

David Greene wrote:
I'm trying to compile this little program:
#include <boost/bind.hpp>
#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 <boost/bind.hpp>
#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