Boost logo

Boost Users :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2006-02-28 02:31:39


On 2/27/06, yinglcs2_at_[hidden] <yinglcs2_at_[hidden]> wrote:
> Hi
> I have a Boost lambda question, I appreciate is
> someone can help me out:
>
> I have a class A:
> class A{
> private:
> B& getB() {return _b;}
> B& _b;
> };
>
> vector<A> aList;
>
> void aFunction (A& a, B& b);
>
> how can I write a loop to walk thru a list of A and
> call aFunction.
>
> for (vector<A>::iterator itr = aList.begin; itr !=
> end; itr++) {
> A a = (*itr);
> aFunction (a, a->getB());
> }
>

For a start, shouldn't it be aFunction(a, a.getB()); - a's got no
operator->. If so, use this

std::for_each(aList.begin(), aList.end(),bind(&aFunction, _1,
bind(&A::getB, _1)));

HTH

Stuart Dootson


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