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: Wednesday, October 05, 2005 10:41 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [bind] Member fn has defeated me
BRIDGES Dick wrote:
BRIDGES Dick wrote:
class Bar { typedef void (*pf)(bool);
If you make this
typedef boost::function
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.
[...]
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.
Works fine now. I don't know why I find boost::bind so mysterious, but I *WILL* learn! Thank you for both the answers and your patience. Regards, Dick
BRIDGES Dick wrote: <snip>
Works fine now. I don't know why I find boost::bind so mysterious, but I *WILL* learn!
Thank you for both the answers and your patience.
Regards, Dick
You find it mysterious because it's not even slightly common outside of functional languages. (I hope Boost can change this). Basicly: bind is a function that creates a function (sortof) from a function and arguments. Confused? Don't worry, that's normal. Essentially: bind(&X::f, &x, _1); is the same as: f_result_type bound_f(f_arg1_type arg1) { return x.f(arg1); } // ... &bound_f but with less hassles (ie. x can be local)
participants (2)
-
BRIDGES Dick
-
Simon Buchan