Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-04-16 16:10:19


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 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