Download presentation
Presentation is loading. Please wait.
Published byStewart Hensley Modified over 6 years ago
1
Inheritance and Big O And your first reading assignment
And any questions about the current homework assignment
2
Reading assignment For next Monday (Sept 18), you should read Chapter 10 as well as any other sections listed in the “prerequisites” that you need to understand chapter 10 There will be a quiz on this material, covering key ideas and concepts
3
Homework 1 Your first homework assignment is due by the end of the day on Wednesday Any last-minute questions?
4
or virtual void react() override {
5
Dynamic dispatch The specific function implementation to use for a function call is resolved at run time Polymorphism: "In programming languages and type theory, polymorphism (from Greek πολύς, polys, "many, much" and μορφή, morphē, "form, shape") is the provision of a single interface to entities of different types.[1] A polymorphic type is one whose operations can also be applied to values of some other type, or types.[2]" (Thank you, Wikipedia)
6
Dynamic dispatch The specific function implementation to use for a function call is resolved at run time Polymorphism: "In programming languages and type theory, polymorphism (from Greek πολύς, polys, "many, much" and μορφή, morphē, "form, shape") is the provision of a single interface to entities of different types.[1] A polymorphic type is one whose operations can also be applied to values of some other type, or types.[2]" (Thank you, Wikipedia) The actual function executed from a function call depends on the types involved in that function call
9
Dynamic dispatch: how?? If a class has at least one virtual function, it will have a vtable Each instance of a class with a virtual method will have a pointer to the vtable stored inside of it When a virtual function is called, the vtable pointer is checked The vtable associates a specific function implementation with each virtual function that the object has Based on the value in the vtable, the appropriate function is called
10
Pure virtual function: A virtual function with explicitly no implementation
11
Abstract class: A class with at least one pure virtual member function
12
Abstract class: A class with at least one pure virtual member function
13
Pure abstract class: A class with only pure virtual member functions
16
Constructors and Destructors
Constructors are run from the top down in the inheritance heirarchy Destructors are run from the bottom up If you use inheritance or have any virtual methods, you always should have a virtual destructor
17
Inheritance Inheritance is a powerful way to use abstraction to reduce complexity We will be using inheritance (usually in the form of pure abstract classes) throughout this class Any questions?
18
Measuring performance: Big O notation
Big O notation is used to describe the runtime performance of algorithms as the problem size changes Often care about either the amount of time taken, or the amount of memory used (or both) Let's take a look at how we can figure out what the big O value is…
19
Biggest item algorithm
int largest(int data[], int n) Takes in an array and a size Returns largest item in the array Can safely assume array has at least one item
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.