15.2.1. Defining a Base Class
We’ll start by completing the definition of our Quote
class:
class Quote {public: Quote() = default; // = default see § 7.1.4 (p. 264) Quote(const std::string &book, double sales_price): bookNo(book), price(sales_price) { } std::string isbn() const { return bookNo; } // returns the total sales price for the specified number of items // derived classes will override and apply different discount algorithms virtual double net_price(std::size_t n) const { return n * price; } virtual ~Quote() = default; // dynamic binding for the destructorprivate: std::string ...
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.