O'Reilly logo

C++ Primer, Fifth Edition by Barbara E. Moo, Josée Lajoie, Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Message Class

Given this design, we can write our Message class as follows:

class Message {    friend class Folder;public:    // folders is implicitly initialized to the empty set    explicit Message(const std::string &str = ""):        contents(str) { }    // copy control to manage pointers to this Message    Message(const Message&);            // copy constructor    Message& operator=(const Message&); // copy assignment    ~Message();                         // destructor    // add/remove this Message from the specified Folder's set of messages    void save(Folder&);    void remove(Folder&);private:    std::string contents;      // actual message text    std::set<Folder*> folders; // Folders that have this Message    // utility functions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required