Re: space in string
"George" <George@discussions.microsoft.com> wrote in message
news:9592DA0A-95F8-463E-ADC4-58037C369EFD@microsoft.com
Thanks for so much information. Suppose in your code for class
string, there are two functions, foo and goo, foo invokes goo.
When you say "in your code for class string", you mean foo and goo are
some member functions of string, right?
Then,
1. In goo, it allocates a string, small. In your point, it should be
on the stack on function goo, right?
goo doesn't allocate anything. The memory is already set aside inside
the string object, at the time that object is constructed. goo simply
initialize this memory to some valid value.
2. Goo returns the string by reference to foo;
Pardon? Goo is a member of string class, isn't it? If so, your statement
makes no sense. Or, are you saying the arrangement is something like
this:
string& goo() {
string s;
// Do something
return s;
}
This would be illegal regardless of how string is implemented
internally: you can't return references to local variables.
3. Then foo will refer to some space in goo function stack, which is
unwound when goo returns.
Since the setup for your scenario is meaningless, the conclusion is
moot.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925