A class or function which can operate any type of with single bunch of code (Run time data type initialization)
Template is one of the features
added to C++ recently. It is a new concept which enable programmer to make generic
class which can operate any data type. A Template class takes data type as an
argument which run time set data type of calling object so there is no need to
make different version of class and function different types of data type.
Syntax:
Template
<Class name Ob_Name>
Class
Class_name
{
_____
_____
}
A template can be considered as a
kind of macros. When an object of a specific type is defined for actual use. The
template definition for that class is substituted with the required data type. since
a template is defined with a parameter that would be replaced by a specific
data type at the time of actual use of the class or function. The template is sometimes called
parameterized or function.
/* ##############################
Girfa Student Help
Template Class
Date : 21-Sep-2016
for more example visit: http://girfahelp.blogspot.in/p/c-tutorial_20.html
###############################
*/
#include<iostream.h>
#include<conio.h>
const int size=3;
template <class t>
class vector
{
t *v;
public:
vector()
{
v=new t[size];