- To: coders@xxxxxxxxxxx
- Subject: Re: [coders] C++ std::string question
- From: Erik de Castro Lopo <mle+slug@xxxxxxxxxxxxx>
- Date: Fri, 20 Oct 2006 20:15:01 +1000
- Organization: Erik Conspiracy Secret Labs
- Reply-by: Fri Mar 4 18:43:51 EST 2000
Sam Lawrance wrote:
> You can't return a reference to s, because it goes out of scope as soon
> as the function exits. You could return a copy of s by value, or a
> pointer to a heap allocated copy.
Ah, ok, something like this:
std::string
return_string (void)
{
std::string s = "asdasd" ;
return s ;
}
Thanks Sam.
Cheers,
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"One in four [British] Muslims sympathises with motives of terrorists."
-- http://www.telegraph.co.uk/news/main.jhtml?xml=/news/2005/07/23/npoll23.xml