[bind] Member fn has defeated me
void foo(bool){}
struct X {
void f(bool b) {}
}
class Bar {
typedef void (*pf)(bool);
public:
Bar(pf fn){
fn(true);
}
};
int main( int argc, char **argv ) {
Bar bar_(foo); // ok.
X x;
Bar bar_(boost::bind(&X::f, &x)()); // compile fails.
/*LOTS* of other failed attempts with various errors. 8(
return(0);
}
BRIDGES Dick wrote:
class Bar { typedef void (*pf)(bool);
If you make this
typedef boost::function
public: Bar(pf fn){ fn(true); } };
int main( int argc, char **argv ) {
Bar bar_(foo); // ok.
X x; Bar bar_(boost::bind(&X::f, &x)()); // compile fails.
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.
participants (2)
-
BRIDGES Dick
-
Peter Dimov