C++中函数模板显示具体化问题大家快来看看啊~(已解决)
#include<iostream>using namespace std;
template <class T>
void ShowArray(T arr[],int n);
struct debts
{
char name[50];
double amount;
};
template <> void ShowArray<char *>(char * arr[],int n);
int main(void)
{
int things[6]={13,31,103,301,310,130};
struct debts mr_E[3]=
{
{"Ima Wolfe",2400.0},
{"Ura Foxe ",1300.0},
{"Iby Stout",1800.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 T>
void ShowArray(T arr[],int n)
{
T sum=0;
cout<<"template A\n";
for(int i=0;i<n;i++)
sum=sum+arr[i];//1有错
cout<<"Sum things are "<<sum<<endl<<endl;
}
template <> void ShowArray<char *>(char * arr[],int n)
{
double sum=0;
cout<<"template B\n";
for(int i=0;i<n;i++)
sum=sum+*arr[i];
cout<<"Sum debts are "<<sum<<endl<<endl;
}
请帮我把程序改正确,能够指点一下更加感谢啊~
[[it] 本帖最后由 沿途有鬼 于 2008-8-5 18:08 编辑 [/it]]