C++中函数模板重载显示具体化问题大家快来看看啊~(跪求答案)

来源:百度知道 编辑:UC知道 时间:2024/06/24 06:01:12
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);//1有错
return 0;
}

template <class T&g

#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()
{
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;