17 Templates

All men are mortal.

Aristotle is a man.

Therefore, Aristotle is mortal.

All X’s are Y.

Z is an X.

Therefore, Z is Y.

All cats are mischievous.

Garfield is a cat.

Therefore, Garfield is mischievous.

A SHORT LESSON ON SYLLOGISMS

Introduction

This chapter discusses C++ templates. Templates allow you to define functions and classes that have parameters for type names. This will allow you to design functions that can be used with arguments of different types and to define classes that are much more general than those you have seen before this chapter.

Prerequisites

Section 17.1 uses material from Chapters 2 through 5 and Sections 7.1, 7.2, and 7.3 of Chapter 7. It does not use any material on classes. Section 17.2 uses material from Chapters 2 through 7 and 10 through 12.