













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














l Base class declares that the function is virtual: virtual void draw() const; l Remember it means draw() exists in essence l Such a declaration tells compiler “I don’t know how this function is implemented, so wait until it is used in a program, and then get its implementation from the object instance .” l The instance will exist in fact (eventually)
double Sale::savings(const Sale &other) const { return (bill() – other.bill()); } bool operator < (const Sale &first, const Sale &second) { return (first.bill() < second.bill()); }
DiscountSale d1, d2; d1.savings(d2); // calls Sale’s savings function
Figure *ptr = new Rectangle, &ref = *new Rectangle('Q', 5, 10, 4); ptr->printAt(1); ref.printAt(1);
Dog d; Pet p; d.name = "Tiny"; d.breed = "Mutt"; p = d; // “slicing” here
~mikec/cs32/demos/ class Pet { public: // pls excuse bad info hiding string name; virtual void print(); }; class Dog : public Pet { public: string breed; virtual void print(); };
d = static_cast
l Idea: a ClockRadio is a Radio and an AlarmClock