Templates As Parameters
You’ve seen that a template can have type parameters, such as typename T
, and non-type parameters, such as int n
. A template can also have a parameter that is itself a template. Such parameters are yet another template feature addition that is used to implement the STL.
Listing 14.21 shows an example that begins with these lines:
template <template <typename T> class Thing>class Crab
The template parameter is template <typename T> class Thing
. Here template <typename T> class
is the type, and Thing
is the parameter. What does this imply? Suppose you have this declaration:
Crab<King> legs;
For this to be accepted, the template argument King
has to be a template class whose declaration matches that of the template parameter ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.