Objectives
This section introduces the notion of
generic types.
Generic types come in two flavors, as polymorphic types that result from inheritance;
and as template classes.
The pointer may be considered
as a degenerate form of a generic type.
The examples of a generic list and a generic stack are used
to illustrate the differences between
the two approaches.
Points to emphasize
- polymorphic types -- due to inheritance
- parametrized types --
corresponding to template classes
Possible difficulties
The use of as a generic type pointer
requires some understanding of the notion
of types as constraints.
You may also need to explain the use of typedef.
Hints
Explain the meaning of a type as the
characterization of a set of individual
elements.
Subtypes delimit a subset thereof.
The intuition is that the more information
you get, the more precisely may you delimit
the set of individuals belonging to the type.
Question
- What are generic types?
Why are they useful?
Explain how C++ supports generic types.
Give an example.
Comments
You may comment on the fact that version
2.0 of C++ does not support template classes,
whereas parametrized classes were
available in Eiffel from the start.
In fact, many C++ libraries
still offer generic classes as macros.
See section [libraries].