Boost logo

Boost Users :

Subject: Re: [Boost-users] lambda::bind and abstract class - how to?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2010-03-05 09:37:56


On Fri, Mar 5, 2010 at 1:33 PM, Archie14 <admin_at_[hidden]> wrote:

> Here is the sample that fails to compile. Complain is about foo being
> abstract
> in IA. Any advise of how to make it work will be greatly appreciated.
>
> #include <boost/lambda/lambda.hpp>
> #include <boost/lambda/bind.hpp>
> #include <boost/ptr_container/ptr_vector.hpp>
>
> class IA
> {
> public:
> virtual int foo() const = 0;
> };
>
> class B : public IA
> {
> public:
> B (int a) : _a(a) {};
> int foo() const {return _a;}
> private:
> int _a;
> };
>
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> boost::ptr_vector<IA> lst;
> lst.push_back(new B(1));
> lst.push_back(new B(2));
>
> boost::ptr_vector<IA>::iterator it =
> std::find_if (lst.begin(),
> lst.end(),
> boost::lambda::bind(&IA::foo,
> boost::lambda::_1) == 1);
> return 0;
> }
>
>
Replacing boost::lambda::_1 with &boost::lambda::_1 makes my compiler (gcc
4.1.1) stop
complaining. Is that what you need?

- Rob.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net