www.umbc.edu
CMSC202 Computer Science II for Majors
Lecture 15 –
Polymorphism (Continued)
- Dr. Katherine Gibson
Computer Science II for Majors Lecture 15 Polymorphism (Continued) - - PowerPoint PPT Presentation
CMSC202 Computer Science II for Majors Lecture 15 Polymorphism (Continued) Dr. Katherine Gibson www.umbc.edu Last Class We Covered Review of inheritance Overriding (vs overloading) Understanding polymorphism Limitations of
www.umbc.edu
www.umbc.edu
2
www.umbc.edu
www.umbc.edu
g++ -Wall -ansi –g -c test1.cpp In file included from test1.cpp:4: TrainCar.h:49: error: expected constructor, destructor,
4
www.umbc.edu
5
www.umbc.edu
www.umbc.edu
7
www.umbc.edu
8
www.umbc.edu
9
www.umbc.edu
www.umbc.edu
SUV SUV Jeep Van Jeep Sedan Sedan SUV
11
www.umbc.edu
12
www.umbc.edu
SUV SUV Jeep Van Jeep Sedan Sedan Van
13
www.umbc.edu
SUV SUV Jeep Van Jeep Sedan Sedan Van *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr
14
www.umbc.edu
SUV SUV Jeep Van Jeep Sedan Sedan Van *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr SUV virtual table Jeep virtual table Van virtual table Sedan virtual table
15
www.umbc.edu
SUV SUV Jeep Van Jeep Sedan Sedan Van *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr SUV virtual table * to SUV::Drive(); Jeep virtual table * to Jeep::Drive(); Van virtual table * to Van::Drive(); Sedan virtual table * to Sedan::Drive();
16
www.umbc.edu
SUV SUV Jeep Van Jeep Sedan Sedan Van *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr *__vptr SUV virtual table * to SUV::Drive(); Jeep virtual table * to Jeep::Drive(); Van virtual table * to Van::Drive(); Sedan virtual table * to Sedan::Drive();
17
www.umbc.edu
www.umbc.edu
19
www.umbc.edu
20
www.umbc.edu
21
www.umbc.edu
22