#include <iostream.h>
#include <conio.h>
template<class T>
T max(T A[], int dim)
{
T big = A[0];
for (int k = 1; k<dim; k++)
{
if (A[k] > big)
{
bit = A[k];
}
}
return big;
}
int X[10]={99, 123, 16, 200, 85, 27, 33, 80, 11, 73};
float Y[10]={48.17, 16.25 ,-1.27, -0.5, 172.0, 99.1, 2.3, 90.05, -325.79, 14.5};
int main()
{
clrscr();
int ilarge;
ilarge = max(X, 10); //instantiation of max()
cout<<"Maximum of array X = "<<ilarge<<endl
cout<<endl;
float flarge;
flarge = max(Y, 10); //instantiation of max()
cout<<endl;
cout<<"Maximum of array Y = "<<flarge<<endl;
getch();
return 0;
}
|
|

| This program illustrates the function template instantiation where the template parameter list contains both template type and template non-type parameters. |
|
| |
|
|
|
|