Templates in C++

Templates are a type safe way of making generic classes!


Since we want the STL containers to be able to store _any_ class or built in type, we need a mechanism to parameterize the containers. We tell them what type we want to store by saying something like queue q; to create a queue of integers.
There's a problem with Java where you have to cast objects back and forth if you want to store them in the "Vector" class. (This class is different from the built in array classes in both C++ and Java, which are both typesafe).

Vector in Java are not type save
Vector in C++ are type safe
Its good to know how to write templates yourself, but not necessary for understanding how to use them in the STL.
isaac jones
Last modified: Wed May 16 15:41:26 EDT 2001