Template ( class template and function template ) in C++

Template :-It is an additional feature of C++ language by which user can able to prepare generic classes and generic functions. It means generic programming can performed using template. Template is used for preparing family of generic classes or functions e.g. an array class template can prepare all the various type of array class like character array, integer array, float array, double array etc. 
In this way, we can perform multiplication between all types of data types of operands by function template multiplication. A template can be assumed as a macro. When any object is defined by a template then related function definition of that data type is combined with that class or function. Template is also defined with parameters. It is called parameterized class template or parameterized function template. 
Templates are mainly of two types – 
1. Class template     
2. Function template

No comments:

Post a Comment