Through templates we can create generic functions and classes. In a generic function or class, the type of data upon which the function or class operates is specified as a parameter.
Thus, you can use one function or class with several different types of data without having to explicitly re-code specific versions for each data type.

The syntax of the template class is:

template <class T>
class class-name()
//definition of class

In the definition of the class where the generic data type is required, we write T. For example, there is a class in which we want to write int data type. The int is the data type that may be a float or double at different times. For this, T is written wherever we are using int in the class definition.

Sponsored Links

Templates are discussed in detail in lecture 41 and 42 of "Intro to Programming" course. You can read it from there.