Class Templates

In this lesson, we'll learn about the class templates.

A class template defines a family of classes.

Syntax

template < parameter-list > 
class-declaration 		

Explanation

parameter-list: A non-empty comma-separated list of the template parameters, each of which is either a non-type parameter, a type parameter, a template parameter, or a mixture of any of those.

class-declaration: A class declaration. The class name declared becomes a template name.

Instantiation

The process of substituting the template parameters with the template arguments is called instantiation.

In contrast to a function template, a class template is not capable of automatically deriving the template parameters. Each template argument must be explicitly specified. This restriction no longer exists with C++17.

Let’s have a look at the declaration of function and class templates:

Get hands-on with 1400+ tech skills courses.