|
Boost Users : |
From: Oleg Smolsky (oleg.smolsky_at_[hidden])
Date: 2005-07-28 18:52:39
Hello Stuart,
Stuart Dootson wrote on 29/07/2005 at 11:30 a.m.:
> When using boost.bind, a method is effectively treated as a function
> with an unstated first parameter (i.e. this). So, if we have the
> following declarations:
>
> struct A
> {
> void AMethod(std::string const& a, std::string const& b);
> };
>
> void AFunction(A object, std::string const& a, std::string const& b);
Right, that makes sense.
> Think about if you contructed a function object by hand:
>
> struct FuncObj
> {
> FuncObj(std::string const& str1, std::string const& str2) :
> str1_(str1), str2_(str2) {}
>
> void operator()(A object) { AFunction(object, str1_, str2_); }
>
> std::string str1_;
> std::string str2_;
> };
>
> std::for_each(vecOfA.begin(), vecOfA.end(), FuncObj(s1, s2));
>
> You can see that the string arguments are supplied when you construct
> the function object, while the A parameter is passed into the function
> object when it is called, and passed through to the intended function.
Right, I get it. Thank you for the in-depth explanation!
Best regards,
Oleg.
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