|
Boost Users : |
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2006-03-08 02:25:04
On 3/8/06, yinglcs2_at_[hidden] <yinglcs2_at_[hidden]> wrote:
> Hi,
>
> I am trying to Call for_each with boost::lambda
> library to print out the return value of a function:
>
> vector<A> aList;
>
> for_each(aList.begin(), aList.end(), cout <<
> bind(&A::getPriority, _1) );
>
> This can't compile. can yo please tell me what did I
> do wrong?
>
Without more detail (e.g. error message, what does A look like...),
it's difficult to tell....
Here's a minimal example that *does* compile - where is your code different...
#include <vector>
#include <iostream>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using namespace std;
using namespace boost::lambda;
class A
{
public:
int getPriority() const { return 1; }
};
void x()
{
vector<A> aList;
for_each(aList.begin(), aList.end(),
cout << bind(&A::getPriority, _1) );
}
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