CS246 Lecture 17: Lesson 17
Document Summary
Depending on pointer type, the object will behave differently, as the compiler uses the type of the pointer to decide which function to run. Compiler uses the type of the pointer (or type of the reference) to decide which method to run. It does not consider the actualtype of the object. So a comic is a comic only if a comic pointer points to it. Declaring the function virtualwithin the superclass with an overrideparameter in the subclass. To ensure correct version of functions are called. Solution: declare the method virtual class book { Virtual methods: chosen based on the actualtypes of the object runtime. Dynamic dispatch: the process of virtual methods being resolved to the correct one at runtime is known as dynamic dispatch. Process of choosing which method to call at runtime based on the type of a value. We use this by putting virtual in the superclass.