Saturday, September 19, 2015

What is template class? Example with example.

Solution:-
Template:-
       Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.

Example:-

#include<iostream.h>
#include<conio.h>
template < class T >
T add ( T x , T y )
{
       return x+y;
}
void main( )
{
       int c=5 , d=6 ;
       cout<< add (c,d)<<endl;
       float e=5.4 , f=3.3 ;
       cout<< add (e,f)<<endl;
       getch();
}

Video Tutorials:-