#include <iostream>
using namespace std ;
template <typename T>
void function_(T val )
{
//only this line works file
cout<<"value is : "<<val<<endl;
//after adding this line compiler points the error
cout<<"and the data type is : "<<T<<endl;
}
With a template function, the T gets replaced with the type that is actually used.
So this: cout<<"and the data type is : "<<T<<endl;
becomes (if you use an int for the type) cout<<"and the data type is : "<< int <<endl;
or (if you use a double for the type) cout<<"and the data type is : "<< double <<endl;
or (if you use a string for the type) cout<<"and the data type is : "<< string <<endl;