DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Instantiating C++ templates

Specializations

A specialization is a particular instance of a template function or data item that overrides the template version. This might be done, for example, to improve performance for specific common cases. Some examples of specializations:

   template <class T> void f(T) {}		// template
   

template<> void f(char* s) {} // specialization

template <class T> struct A {void f();} // template

template<> void A<int>::f() {} // specialization

template <class T> struct B {static int x;}; // template template <class T> int A<T>::x = 37;

template<> int A<double>::x = -59; // specialization

Such specializations are automatically picked up by the link simulation mentioned earlier, and they override general templates.


Next topic: Libraries
Previous topic: Inlines

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004