CS 455 Lecture Notes

Week Eight, Tuesday: Templates

Up until now we have used "typedef" to give flexibility to classes and functions. For example, you could have a "Bag" of nickels, or a Bag of dimes, but you could not have both in the same program. Templates allow us to increase flexibility for software reuse.

Template Functions

Template functions are used where similar actions are performed on a variety of objects or data types (such as sorting). Implementing one function to sort different kinds of objects (that have a comparison member function implemented) is a good example of software productivity improvement through software reuse.


This page established October 1, 1999; last updated October 1, 1999.