On Mon, 03 Nov 2003 17:44:42 GMT, "stub" <st**@asof.com> wrote:
My understanding is that "MyString" is created within the function of "emit"
on stack. How could the value of "MyString" be returned to the caller
successfully?
string emit()
{
string MyString("This is a string from emit()");
return MyString;
}
int main()
{
string YourString;
YourString = emit();
...
}
There will be a temporary string object created from MyString which is
then returned. It is only bad to return a reference or pointer to an
object which is created on the stack because it goes out of scope when
the function returns. The temporary will last until its value is used
by the object to which it is assigned.
--
Bob Hairgrove
No**********@Home.com