CMSC 202 Computer Science II, Spring 2016, Section 01
Lecture 18: Polymorphism
Tue 04/05, 2016
[Up]
[Previous Lecture]
[Next Lecture]
Assigned Reading:
Slides As Shown:
Topics Covered:
- Reviewed for Midterm Exam II.
- Dynamic binding and virtual member functions.
- Used virtual member functions to design an abstract
Array base class with a sorting function. Any class derived
from array can be sorted using sort() without recompiling
the base class functions.
- A hetergeneous linked list can hold different types of
objects in the list at the same time.
The implementation of HList brings up many issues
that come up when you work with virtual functions,
including:
- the need for a virtual destructor
- clone(): a virtual "copy constructor"
- run-time type information
- dynamic type casting
-
Code for HList and the HNode base class:
HList.cpp,
HList.h.
-
IntNode class derived from HNode:
IntNode.cpp,
IntNode.h.
-
Test program #1 and output:
HLtest1.cpp,
HLtest1.txt.
-
DoubleNode class derived from HNode:
DoubleNode.cpp,
DoubleNode.h.
-
StringNode class derived from HNode:
StringNode.cpp,
StringNode.h.
-
Test program #2 and output:
HLtest2.cpp,
HLtest2.txt.
-
Test program #3 and output:
HLtest3.cpp
HLtest3.txt
-
HStack is a private derivation of HList.
HStack.cpp,
HStack.h,
HStack2.h.
-
Stack tested:
HStest1.cpp,
HStest1.txt.
-
FIFO queue implemented. Check out source code for HQueue.
HQueue.cpp,
HQtest1.cpp,
HQtest1.txt,
HQueue.h.
[UMBC] |
[CSEE] |
[CMSC202] |
[CMSC202-06]
Last Modified:
22 Jul 2024 11:29:14 EDT