Thanks Peter, this makes sense. But just image I cannot change the
print function's interface. For example I have to interface with MFC's
CComboBox::AddString( LPCTSTR lpszString ) . Do you think there is
still a way to have just one for_each() loop? My guts tell me no.
Thanks again,
Christian
On 4/16/07, Peter Dimov
Christian Henning wrote:
for_each( as.begin() , as.end() , bind( &print , bind( &std::string::c_str , bind( &A::name, _1 ))));
The problem here is that A::name returns a temporary std::string; the code is similar to
char const * s = it->name().c_str(); print( s );
Since the temporary std::string is destroyed, s remains dangling. One way of avoiding the problem is to make print() take a std::string instead of a char*.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users