#include <iostream>
using namespace std;
template<typename T>
void ShowArray(T arr[] ,int n) ; //模版1
template<typename T>
void ShowArray(T *arr[] ,int n) ; //模版2
struct debts
{
char name[50] ;
double amount ;
};
int main()
{
int things[6] = {13,31,103,301,310,130} ;
struct debts mr_E[3] =
{
{"Im Wolfe",2400.0},
{"Ura Foxe",1300.0},
{"Tby Stout",1800.0}
};
double *pd[3] ;
for(int i=0 ;i<3 ;i++)
pd[i] = &mr_E[i].amount ;
cout<<"Sum of Mr.E's things:\n" ;
ShowArray(things,6) ; //使用模版1
cout<<"Sum of Mr.e's debts:\n" ;
ShowArray(pd,3) ; //使用模版2
return 0;
}
template<typename T>
void ShowArray(T arr[] ,int n) //模版1
{
cout<<"template A\n" ;
T sum = 0;
for(int i =0 ;i < n ;i++)
sum += arr[i] ;
cout<<sum<<endl ;
}
template<typename T>
void ShowArray(T *arr[] ,int n) //模版2
{
T sum=0.0 ;
cout<<"template B\n" ;
for(int i=0;i<n;i++)
sum += *arr[i];
cout<<sum<<endl ;
}