If following is the definition of simple function template:
template<typename T>
T compare(T a, T b)
{
return a>b ? a : b;
}
Can it be called with different template parameter based on some user input during runtime, WITHOUT creating class templates, with different T
values as follows for example:
char type;
cout<<"Enter type: ";
cin>>type;
if( type=='i')
{
int x=compare<int>(3,6);
}
else if( type=='d' )
{
double z=compare<double>(5.1,7.9);
}
..so on