I could use some clarification on destructors.
I understand that if an object contains a pointer to allocated memory, then the object’s destructor should call delete on that pointer. But what if an object contains an object that contains a pointer to allocated memory, such as a string?:
class Foo
{
string bar;
};
Foo* foo = new Foo;
delete foo;
Is there aught I must do to ensure that the underlying char[] in the string is deallocated?
The
stringtype’s destructor is responsible for cleaning up any resource it owns. Your object’s destructor will call the destructors of member objects.