| < Day Day Up > |
|
Static polymorphic behavior is realized at compile time. A class template acts as a generic class definition from which new class types can be defined by a simple change of parameter types. Whereas a normal class is used to create objects, a class template is used to define new class types, from which objects are then created. The compiler uses the types you supply, combined with the class template, to create a wholly new class type.
Understanding how to declare, implement, and use class and function templates will pay big dividends in many ways. Primarily, it provides you with a mechanism to write generic code. Learning to write generic code can potentially save you a lot of work. Another benefit to learning templates is that it opens up to you the world of the C++ Standard Template Library (STS). The STL is a collection of class template components ready for your use. All you have to know to use STL components is an understanding of how class templates work.
In this chapter I will show you how to declare, implement, and use class templates. I will also introduce you to several important STL components and show how you can integrate them into your programs.
| < Day Day Up > |
|