I have a c++ class with a member that is a string, something like:
class Phone {
string name;
void foo()
{
name = string("new_name");
}
}
Now, within the function "foo", I reassign the string to "new_name". My question is:
- What happens to the old, empty string? Is it correctly "freed"? Does it still occupy memory?
- Now I initialize the string in the constructor of Phone to string("old_name"). Is this the same case as with the empty string before? What happens here to the old string "old_name"?