Understanding Template Parameters

Distinguish between various types of template parameters in this lesson.

So far in the course, we have seen multiple examples of templates with one or more parameters. In all these examples, the parameters represented types supplied at instantiation, either explicitly by the user or implicitly by the compiler when it could deduce them. These kinds of parameters are called type template parameters. However, templates can also have non-type template parameters and template template parameters. We’ll explore all of them in this lesson.

Type template parameters

As already mentioned, these are parameters representing types supplied as arguments during the template instantiation. They are introduced either with the typename or the class keyword. There’s no difference between using these two keywords. A type template parameter can have a default value, which is a type. This is specified the same way we would specify a default value for a function parameter. Examples for these are shown in the following snippet:

Get hands-on with 1200+ tech skills courses.