3.2 Template class

A template class (as opposed to a class template) is the use of a class template with the specification of the parameter type. In other words, template LinkedList<T> is a class template, but LinkedList<int> is a template class.

In a source code, the use of template classes only require that the corresponding class template declarations be included. There is no need to include the class template definitions for the compiler to compile code.

Listing 5 is an example of the use of a template class.


Listing 5:templateclass
 
1// this is a test program, call it test.cc 
2#include ”ll.h” 
3 
4int main(void
5{ 
6  LinkedList<int> *pLI; 
7 
8  pLI = new LinkedList<int>(23); 
9  return 0; 
10}