Double Frees in Modern C++
Modern C++ solves this differently:
std::string s1 = "Cpp"; std::string s2 = s1; // Duplicate the data in s1.
- The heap data from
s1is duplicated and
s2gets its own independent copy.
s2go out of scope, they each free their own memory.