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.