- Abstract classes
- Sole purpose: to be a base class (called abstract base classes)
- Incomplete; derived classes fill in ``missing pieces''
- Cannot make objects from abstract class; however, can have pointers and references
- Concrete classes
- Can instantiate objects
- Implement all functions they define
- Provide specifics
- Abstract classes not required, but helpful
- To make a class abstract
- Need one or more ``pure'' virtual functions
- Declare function with initializer of 0
- virtual void draw() const = 0;
- Regular virtual functions; have implementations, overriding is optional
- Pure virtual functions; no implementation, must be overridden
- Abstract classes can have data and concrete functions; required to have one or more pure virtual functions
- Abstract base class pointers; useful for polymorphism
- Application example
- Abstract class Shape; defines draw as pure virtual function
- Circle, Triangle, Rectangle derived
from Shape; each must implement draw
- Screen manager knows that each object can draw itself
- Iterators (more Chapter 21)
- Walk through elements in vector/array
- Use base-class pointer to send draw message to each
2004-07-26