Boost logo

Boost Users :

From: Christian Henning (chhenning_at_[hidden])
Date: 2007-04-16 16:20:58


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 <pdimov_at_[hidden]> wrote:
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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