Boost logo

Boost Users :

Subject: Re: [Boost-users] serialization::make_nvp parameters
From: Luca Cappa (luca.cappa_at_[hidden])
Date: 2009-09-09 08:19:03


On Tue, 08 Sep 2009 19:35:06 +0200, Robert Ramey <ramey_at_[hidden]> wrote:

> I would not expect this to work.
>
> const char* const_temp = temp.c_str( );
>
> provides a cont char * - but this pointer is only temporary and becomes
> invalid when the function creating it returns. Hence the run time error.

I believe const_temp is valid here, up to exit of code block it resides.
Perhaps you confused this code with the following one, which is wrong
because
the temporary 'str' std::string is then destroyed just after it has been
created, i.e.:

const char* const_temp = str( boost::format("x:%1% y:%2%") % _x % _y
).c_str( );

and const_temp points to a data buffer of an already destroyed std::string.

Greetings,
Luca


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