15.8.1. Writing a Basket Class


One of the ironies of object-oriented programming in C++ is that we cannot use objects directly to support it. Instead, we must use pointers and references. Because pointers impose complexity on our programs, we often define auxiliary classes to help manage that complexity. We’ll start by defining a class to represent a basket:

class Basket {public:    // Basket uses synthesized default constructor and copy-control members    void add_item(const std::shared_ptr<Quote> &sale)        { items.insert(sale); }    // prints the total price for each book and the overall total for all items in the basket    double total_receipt(std::ostream&) ...

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.