Topic: Variable scopes


Author: pp000499@interramp.com
Date: 22 Mar 1995 12:45:10 GMT
Raw View
I've been trying to understand when and how dynamic variables get zapped.

For instance, consider a friend string + operator overload function defined as :-

String operator (const String & s1, const String & s2)
{
    String temp;

    // check for errors etc
    // allocate memory etc
    // temp = s1 + s2 etc

    return temp;
}

temp here contains the result of adding s1 and s2 and is return as a result.

Now the question is, how long does temp live for?

if I had a loop where I did a million string additions, does that mean there
will be a million temp string floating about until they go out of scope?

Thanks

MFC