Copy Control for the Message Class

When we copy a Message, the copy should appear in the same Folders as the original Message. As a result, we must traverse the set of Folder pointers adding a pointer to the new Message to each Folder that points to the original Message. Both the copy constructor and the copy-assignment operator will need to do this work, so we’ll define a function to do this common processing:

// add this Message to Folders that point to mvoid Message::add_to_Folders(const Message &m){    for (auto f : m.folders) // for each Folder that holds m        f->addMsg(this); // add a pointer to this Message to that Folder}

Here we call addMsg on each Folder in m.folders. The addMsg function will add a pointer to this Message to that ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.