The Message Destructor
When a Message is destroyed, we must remove this Message from the Folders that point to it. This work is shared with the copy-assignment operator, so we’ll define a common function to do it:
void Message::remove_from_Folders(){ for (auto f : folders) // for each pointer in folders f->remMsg(this); // remove this Message from that Folder folders.clear(); // no Folder points to this Message}
The implementation of the remove_from_Folders function is similar to that of add_to_Folders, except that it uses remMsg to remove the current Message.
Given the remove_from_Folders function, writing the destructor is trivial:
Message::~Message(){ remove_from_Folders();}
The call to remove_from_Folders ensures that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access