18.4. Nontype Parameters

Class template Stack of Section 18.2 used only a type parameter (Fig. 18.1, line 7) in its template declaration. It’s also possible to use nontype template parameters, which can have default arguments and are treated as constants. For example, the C++ standard’s array class template begins with the template declaration:

template < class T, size_t N >

(Recall that keywords class and typename are interchangeable in template declarations.) So, a declaration such as

array< double, 100 > salesFigures;

creates a 100-element array of doubles class-template specialization, then uses it to instantiate the object salesFigures. The array class template encapsulates a built-in array. When you create an array class-template specialization, ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.