This documentation is archived and is not being maintained.

Referencing a Template

Visual Studio .NET 2003

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


template-class-name :
template-name < template-arg-list >
template-arg-list :
template-arg-list , template-arg
template-arg :

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, to reference the MyStack class defined in Member Function Templates:

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.

See Also