[lambda] Binding to abstract class methods

Is it possible to bind to pure virtual methods? Like this struct S { void methodOfS( ) = 0; }; void f( S & s ) { using namespace boost :: lambda; bind( & S :: methodOfS, _1 )( s ); } My compiler seems to be complaining that s is abstract, which is surely not a real limitation! Thanks, Rob.

AMDG Robert Jones wrote:
Is it possible to bind to pure virtual methods? Like this
<snip>
My compiler seems to be complaining that s is abstract, which is surely not a real limitation!
This is a unfortunate problem with Boost.Lambda's return type deduction mechanism. See also http://svn.boost.org/trac/boost/ticket/426. You can work around it by passing a pointer. #include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> struct S { virtual void methodOfS() = 0; }; void f( S & s ) { using namespace boost::lambda; bind(&S::methodOfS, _1)(&s); } In Christ, Steven Watanabe

On Wed, Jul 16, 2008 at 6:20 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Robert Jones wrote:
Is it possible to bind to pure virtual methods? Like this
<snip>
My compiler seems to be complaining that s is abstract, which is surely not a real limitation!
This is a unfortunate problem with Boost.Lambda's return type deduction mechanism. See also http://svn.boost.org/trac/boost/ticket/426.
You can work around it by passing a pointer.
#include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp>
struct S { virtual void methodOfS() = 0; };
void f( S & s ) { using namespace boost::lambda; bind(&S::methodOfS, _1)(&s); }
Thanks for that Steven. That solution has now been used in my real code and works like a charm! I just can't quite get the hang of Boost's tolerance of transparently handling pointers, references or instances without breaking stride. My thought paradigm is still stuck in STL-mode rather than Boost-mode. Cheers, Rob.
participants (2)
-
Robert Jones
-
Steven Watanabe