Template In CPP

Templates are the generic data type. It converts into any type of data type automatically. We do not have to write float, int, char, string etc.

Note: For both the header files iostream and conio you can write constream(common for both).

#include<constream.h>

template
void fun(t n)
{
cout << n << endl;
}
void main()
{
clrscr();
fun(10); //integer
fun(10.48); //float
fun('A');  //character
fun("tanmay"); //string
getch();
}

Output:
10
10.48
A
tanmay

 

 

 

Leave a Reply