![]() |
#2
最近不在2010-03-12 16:08
|

#include<iostream>
using namespace std;
template<class any>
showarray(any array[],int n);
template<class any>
showarray(any *array[],int n);
struct debts
{
char name[50];
double amount;
};
int main(void)
{
int things[6]={13,31,103,301,310,130};
struct debts mr_e[3]=
{
{"I am A",240.0},
{"I am B",120.0},
{"I am C",150.0}
};
double *pd[3];
for(int i=0;i<3;i++)
pd[i]=&mr_e[i].amount;
cout<<"listing mr_e's counts of things: \n";
showarray(things,6);
cout<<"listing mr_e's debts: \n";
showarray(pd,3);
return 0;
}
template<class any>
showarray(any array[],int n)
{
float sum;
cout<<"template A\n";
for(int i=0;i<n;i++)
sum+=arrary[i];
cout<<"sum="<<sum;
cout<<endl;
return sum;
}
template<class any>
showarray(any *array[],int n)
{
float sum;
cout<<"template A\n";
for(int i=0;i<n;i++)
sum+=*arrary[i];
cout<<"sum="<<sum;
cout<<endl;
return sum;
}
using namespace std;
template<class any>
showarray(any array[],int n);
template<class any>
showarray(any *array[],int n);
struct debts
{
char name[50];
double amount;
};
int main(void)
{
int things[6]={13,31,103,301,310,130};
struct debts mr_e[3]=
{
{"I am A",240.0},
{"I am B",120.0},
{"I am C",150.0}
};
double *pd[3];
for(int i=0;i<3;i++)
pd[i]=&mr_e[i].amount;
cout<<"listing mr_e's counts of things: \n";
showarray(things,6);
cout<<"listing mr_e's debts: \n";
showarray(pd,3);
return 0;
}
template<class any>
showarray(any array[],int n)
{
float sum;
cout<<"template A\n";
for(int i=0;i<n;i++)
sum+=arrary[i];
cout<<"sum="<<sum;
cout<<endl;
return sum;
}
template<class any>
showarray(any *array[],int n)
{
float sum;
cout<<"template A\n";
for(int i=0;i<n;i++)
sum+=*arrary[i];
cout<<"sum="<<sum;
cout<<endl;
return sum;
}