What is a virtual member?
A virtual member in a base class expects its derived class define its own version. In particular base classes ordinarily should define a virtual destructor, even if it does no work.
How does the protected access specifier differ from private?
- private member: base class itself and friend can access
- protected members: base class itself, friend and derived classes can access
Define your own versions of the Quote class and the print_total function.
Which of the following declarations, if any, are incorrect? Explain why.
class Base { ... }; (a) class Derived : public Derived { ... }; (b) class Derived : private Base { ... }; (c) class Derived : public Base;
- (a): incorrect, deirve from itself.
- (b): incorrect, this is a definition not a declaration.
- (c): incorrect, A derived class is declared like any other class. The declaration contains the class name but does not include its derivation list.
Define your own version of the Bulk_quote class.
Test your print_total function from the exercises in § 15.2.1 (p. 595) by passing both Quote and Bulk_quote objects o that function.
Define a class that implements a limited discount strategy, which applies a discount to books purchased up to a given limit. If the number of copies exceeds that limit, the normal price applies to those purchased beyond the limit.