Example & Tutorial understanding programming in easy ways.

What is class template in C++ ?

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: 

template<class T> 

class classname 

// body of class; 

}; 

Syntax of a object of a template class: 

classname<type> objectname(arglist);

Read More →