What is a class template?

A class template is used to create a family of classes and functions. For example, we can create a template of an array class which will enable us to create an array of various types such as int, float, char, etc. Similarly, we can create a template for a function, suppose we have a function add(), then we can create multiple versions of add().

The syntax of a class template:

  1. template<class T>  
  2. class classname  
  3. {  
  4.   // body of class;  
  5. };  

Syntax of a object of a template class:

  1. classname<type> objectname(arglist);