Using Template Classes

To use the class, the programmer must fill in a value for T. Here we see the programmer creating a list of double precision values. This is indicated by the type name double appearing between angle brackets in the declaration on the first line.

Since the compiler knows what type of elements are being held by the list, it can perform very strong type checking, ensuring that only doubles are inserted into the list, and that when values come out of the list they are the correct type.

[audio] [real] Text to accompany slide16, in Chapter 15 of An Introduction to Object-Oriented Programming