
28 Nov
2006
28 Nov
'06
3:13 p.m.
rodolfo@rodsoft.org wrote:
Hi, I'm trying to put a simple lambda functor which uses pointer to member function into a boost::function like this:
struct aux { int a() const { return 5; } };
int main() { function<int(const aux &)> f = &_1->*&aux::a; }
But the compiler chokes at the assignment with the error:
/usr/include/boost/function/function_template.hpp:119: error: cannot convert 'boost::lambda::detail::member_pointer_caller<int, const aux*, int (aux::*)()const>' to 'int' in return
Try function<int(const aux &)> f = (&_1->*&aux::a)(); or function<int(const aux &)> f = bind( &aux::a, _1 ); or function<int(const aux &)> f = &aux::a;