inheritance and dynamic dispatching substituting derived for base is OK "An instance of a derived class can always be substituted for an instance of a base class." examples: If I ask you for cake and you give me a chocolate cake, I'll be satisfied. However, if I'm being specific and ask you for a cheesecake, and you give me any old cake, I'll be a little disappointed. If a function expects a Point and you pass a ColorPoint, it's alright, since anything you can do with a Point can be done with a ColorPoint. (For instance, any Point method can be called on a ColorPoint, because these methods are inherited.) However, if a function expects a ColorPoint, you cannot pass a Point, because the function might take advantage of ColorPoint-specific features which a Point does not have, e.g. method getColor(). void expectsPoint(const Point &p) { double x = p.getX(), y = p.getY(); Color c = p.getColor(); // *** illegal *** } void expectsColorPoint(const ColorPoint &p) { Color c = p.getColor(); } int main() { ColorPoint cp; Point p; expectsPoint(cp); expectsColorPoint(cp); expectsPoint(p); expectsColorPoint(p); // *** illegal *** } substituting with pointers, references a base class pointer can point to a derived class instance a base class reference can be made an alias to a derived class instance // pointers ColorPoint *cpPtr, cp; Point *pPtr, p; pPtr = &p; // legal cpPtr = &cp; // legal pPtr = &cp; // legal, now we know cpPtr = &p; // *** illegal *** // references Point &pRef1 = p; // legal ColorPoint &cpRef1 = cp; // legal Point &pRef2 = cp; // legal, now we know ColorPoint &cpRef2 = p; // *** illegal *** Why dynamic dispatching? (Slide R-11, "Contrast") for subclass-specific behavior for a single method collection of Mammal objects vs. collection of Mammal ptrs. dispatching rules, complete (see link on section page)