SImple Boost Lambda problem using arguement as object.

This piece of sample code demonstrates my problem quite well: #include <boost/lambda/lambda.hpp> #include <vector> #include <string> #include <iostream> using boost::lambda::_1; class A { std::string s; public: A(std::string sIn):s(sIn){} void print_A() { std::cout<<"A="<<s<<std::endl; } }; int main() { std::string in; std::vector<A *> alist; while(in!="end") { in=""; std::getline(std::cin,in); alist.push_back(new A(in)); } std::for_each(alist.begin(),alist.end(), _1->print_A()); // This is line 30 return 1; } ---- Using g++ ( 3.??) and the latest boost, I get this error: main.cpp: In function `int main()': main.cpp:30: error: base operand of `->' has non-pointer type `const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' Can anyone explain how to fix this? Thanks -- Thad

On 7/26/05, Thaddeus Olczyk <doctlo-boost@yahoo.com> wrote:
This piece of sample code demonstrates my problem quite well:
<snip>
std::for_each(alist.begin(),alist.end(), _1->print_A()); // This is line 30
I think you'll have to use bind(&A::print_A, _1) instead
return 1; } -- Thad
Stuart Dootson

Thaddeus Olczyk wrote:
std::for_each(alist.begin(),alist.end(), _1->print_A()); // This is line 30
I think you have to use a binder here: http://www.boost.org/doc/html/lambda/le_in_details.html#member_functions_as_...
participants (3)
-
Stuart Dootson
-
Thaddeus Olczyk
-
Zeljko Vrba