15.8.1. Writing a Basket Class

Image

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.