< previous page page_403 next page >

Page 403
Hour 23
Templates
In the past few years, C++ has added a few new features. One of the more exciting and powerful new aspects of C++ is templates. Templates enable you to build type-safe collections. In this hour you will learn
· What templates are and how to use them
· Why templates supply a better alternative to macros
· How to create class templates
What Are Templates?
In Hour 19, you learned how to make a linked list. Your linked list was nicely encapsulated: the list knew only about its head pointer; the head pointer delegated its work to internal pointers, and so forth.
The one glaring problem with the linked list was that it only knew how to handle the particular data objects it was created to work with. If you wanted to put anything else into your linked list, you couldn't do it. You couldn't for <?>xample, make a linked list of Car objects, or of Cats, or of any other object <?>t wasn't of the same type as those in the original list.

 
< previous page page_403 next page >

If you like this book, buy it!