Boost logo

Boost Users :

From: Joao Abecasis (jpabecasis_at_[hidden])
Date: 2005-02-18 21:44:52


Delfin Rojas wrote:
> While this solves most of my problems I still cannot make it work for this
> other case:
>
> shared_ptr<CFoo> pFoo(new CFoo);
> std::vector<int> vnValues(10, 1);
> std::for_each(vnValues.begin(), vnValues.end(),
> boost::lambda::bind(&CFoo::SetI, pFoo, boost::lambda::_1));
>
> I tried dereferencing pFoo but it didn't work.

My guess is that CFoo::SetI is not a const member function. Because
*pFoo is being passed by const reference, compilation fails. You can
workaround this in one of the following ways:

     boost::lambda::bind(&CFoo::SetI,
         pFoo.get(), // returns a raw pointer
         boost::lambda::_1));

     boost::lambda::bind(&CFoo::SetI,
         boost::ref(*pFoo), // wrap *pFoo so it is passed
                            // by (non-const) reference
         boost::lambda::_1));

     boost::lambda::bind(&CFoo::SetI,
         boost::lambda::var(*pFoo), // wrap *pFoo so it is passed
                                    // by (non-const) reference
         boost::lambda::_1));

HTH,

Best regards,

Joćo Abecasis


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