Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2004-11-30 11:23:20


<John.Wismar_at_[hidden]> wrote in message
news:OFC9B3D7E7.C7CE5726-ON86256F5C.0056B6A6-86256F5C.00591277_at_AUTOZONE.COM...
> I'm taking a look at the Lambda library, and writing some toy programs,
and
> I keep coming up with errors, and I can't figure out what the problems
> are....
>
> Example 1:
> This works as expected:
>
> using namespace boost::lambda;
>
> class Foo {
> public:
> void print() {
> std::cout << "Foo::print()\n";
> }
> };
>
> template <class Container, class Function>
> Function for_all(Container cont, Function f) {
> return std::for_each(cont.begin(), cont.end(), f);
> }
>
> int main(int argc, char* argv[]) {
> std::vector<Foo> vec;
> //Fill vec
> for_all(vec, (bind(&Foo::print, _1)));
> return 0;
> }
>
> If I change the declaration of for_all to take the container by const
> reference, I get errors [See Error 1 pasted in below]:

As you should, because Foo::print() is a non-const member function.

Jeff F


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