I know that a "deleting the same memory twice" error can happen when two
pointers address the same dynamically allocated object. If delete
is
applied to one of the pointers, then the object’s memory is returned to the
free store. If we subsequently delete the second pointer, then the free
store may be corrupted.
But why doesn't this code cause a run-time error?
string *str_1 = new string;
auto str_2 = str_1;
*str_1 = "AAA";
cout<<*str_2<<endl;
delete str_1;
delete str_2; // No Error
// Prints AAA