Re: [Boost-users] [bind] Member fn has defeated me
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: Tuesday, October 04, 2005 3:49 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [bind] Member fn has defeated me
BRIDGES Dick wrote:
class Bar { typedef void (*pf)(bool);
If you make this
typedef boost::function<void(bool)> pf;
[snip]
then
Bar bar_( boost::bind(&X::f, &x) );
should work. But you can't get an oridnary function pointer from boost::bind; a function pointer doesn't have enough state to represent &X::f + &x.
<error_message> Building file: ../main.cpp g++ -D_REENTRANT -I/boost_1_33_0 -O0 -g3 -Wall -c - fmessage-length=0 -omain.o ../main.cpp /boost_1_33_0/boost/bind.hpp: In instantiation of ?boost::_bi::result_traits<boost::_bi::unspecified, void (X::*)(bool)>?: /boost_1_33_0/boost/bind/bind_template.hpp:15: instantiated from ?boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> > >? ../main.cpp:197: instantiated from here /boost_1_33_0/boost/bind.hpp:63: error: ?void (X::*)(bool)? is not a class, struct, or union type /boost_1_33_0/boost/bind/bind_template.hpp: In instantiation of ?boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> > >?: ../main.cpp:197: instantiated from here /boost_1_33_0/boost/bind/bind_template.hpp:15: error: no type named ?type? in ?struct boost::_bi::result_traits<boost::_bi::unspecified, void (X::*)(bool)>? ... [previous line repeated 23 times - increasing __LINE__] ... /boost_1_33_0/boost/function/function_template.hpp: In static member function ?static void boost::detail::function::void_function_obj_invoker1<Functio nObj, R, T0>::invoke(boost::detail::function::any_pointer, T0) [with FunctionObj = boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> > >, R = void, T0 = bool]?: /boost_1_33_0/boost/function/function_template.hpp:479: instantiated from ?void boost::function1<R, T0, Allocator>::assign_to(FunctionObj, boost::detail::function::function_obj_tag) [with FunctionObj = boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*>
, R = void, T0 = bool, Allocator = std::allocator<void>]? /boost_1_33_0/boost/function/function_template.hpp:430: instantiated from ?void boost::function1<R, T0, Allocator>::assign_to(Functor) [with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> > >, R = void, T0 = bool, Allocator = std::allocator<void>]? /boost_1_33_0/boost/function/function_template.hpp:294: instantiated from ?boost::function1<R, T0, Allocator>::function1(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> , R = void, T0 = bool, Allocator = std::allocator<void>]? /boost_1_33_0/boost/function/function_template.hpp:638: instantiated from ?boost::function<R ()(T0), Allocator>::function(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> , R = void, T0 = bool, Allocator = std::allocator<void>]? ../main.cpp:197: instantiated from here /boost_1_33_0/boost/function/function_template.hpp:136: error: no match for call to ?(boost::_bi::bind_t<boost::_bi::unspecified, void (X::*)(bool), boost::_bi::list1<boost::_bi::value<X*> > >) (bool&)? make: *** [main.o] Error 1 </error_message>
Peter, Your suggestion sure made sense. I clearly did something wrong but can't figure out what that would be. I must be interpreting the error message incorrectly. I interpret it to say that the compiler can't find the definition of X but X x; x.f(true); compiles without any problem. Where should I be looking? Regards, Dick
BRIDGES Dick wrote:
BRIDGES Dick wrote:
class Bar { typedef void (*pf)(bool);
If you make this
typedef boost::function<void(bool)> pf;
[snip]
then
Bar bar_( boost::bind(&X::f, &x) );
should work. But you can't get an oridnary function pointer from boost::bind; a function pointer doesn't have enough state to represent &X::f + &x.
<error_message>
[...] I omitted too much of the context, sorry ;-) For struct X { void f(bool b) {} } the correct thing would be to use boost::bind(&X::f, &x, _1) so that the bool argument from pf (the first input argument is _1 in bind notation) can be passed to X::f.
participants (2)
-
BRIDGES Dick
-
Peter Dimov