
16 Apr
2007
16 Apr
'07
8:10 p.m.
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*.