Exploring template parameters and arguments
We learned about function and class templates and their instantiations in the previous three sections. We know that, when defining a template, its parameter list needs to be given. While we instantiate it, the corresponding argument list must be provided. In this section, we will further study the classifications and details of these two lists.
Template parameters
Recall the following syntax, which is used to define a class/function template. There is a <>
symbol after the template
keyword, in which one or more template parameters must be given:
//class template declaration
template <
parameter-list> class-declaration //function template declaration template <parameter-list> function-declaration
A parameter inside the parameter list could be one of the following three types:
- Non-type template parameter: Refers to the compile-time constant values, such as integers and pointers, that reference static entities...