8.8
#include
using namespace std;
template
T SumArray(T arr[],int n)
{
T sum=0;
for(int i=0;i<n;i++)
sum+=arr[i];
return sum;
};
template
T SumArray(T *arr[],int n)//arr是指向指针数组的指针
{
T sum=0;
for(int i=0;i<n;i++)
sum+=*arr[i];//arr[i]是一个指针,+*之后才是其中的数值;
return sum;
};
struct debts{
char name[20];
double amount;
};
void main87()
{
int things[6]={13,31,103,301,310,130};
struct debts mr_E[3]={
{“Ima 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<<”The sum is”<<SumArray(things,6)<<endl;
cout<<”The sum is”<<SumArray(pd,3)<<endl;
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案88/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!