#include <iostream.h>
#include<conio.h>
template <class T>
T max(T x, T y)
{
return (x>y) ? x : y;
}
template<class U>
U max(U &A, U size)
{
U big
big= A[0];
for (int i=0; i<size; i++)
{
if (*A>big)
{
big=*A;
}
*A++;
}
return big;
}
int main()
{
clrscr();
int arr[5]={16, 95 ,38 ,72, 47};
int a = 40, b = 80;
int l1, l2;
int sz ;
sz = sizeof(arr);
cout<< "Maximum(a,b) = "<<max(a, b)<<endl;
cout<<"Largest element of array is "<<max(&arr,sz)<<endl;
getch();
return 0;
}
|
|

| This program illustrates the overloaded function templates. |
|
| |
|
|
|
|