Search⌘ K
AI Features

Class Templates

Learn to define and instantiate class templates using type and non-type parameters. Understand method templates inside classes, inheritance complexities, and alias templates to enhance code reuse and performance in embedded C++ programming.

A class template will be defined by placing the keyword template in front of the class template followed by type or non-type parameters.

  • The parameters are declared by class or typename.
  • The parameter can be used in the class body
  • You can define the methods of the class template inside or outside the class.
C++
template <typename T, int N>
class Array{
T elem[N];
...

Instantiation

The process of substituting the template parameter by the template arguments is called instantiation. In contrast to a function template, a class template is ...