Referencing a Template

To reference a template class or function use the following syntax:

Syntax

template-class-name :

template-name < template-arg-list >

template-arg-list :

template-arg
template-arg-list , template-arg

template-arg :

expression
type-name

All template-arg arguments must be constant expressions. The compiler creates a new instance (called an instantiation) of the templated class or function if there is no exact match to a previously generated template. For example:

MyStack< unsigned long, 5 > stack1;     // creates a stack of 
                                        // unsigned longs
MyStack< DWORD, 5 >   stack2;    // uses code created above
MyStack< char, 6 > stack3;    // generates new code
MyStack< MyClass, 6 > stack4;   // generates stack of MyClass objects

Each generated template function creates its own static variables and members.