64,651
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
template <typename T>
void ShowArray (T arr[], int n);
template <typename T>
void ShowArray(T * arr[], int n);
struct debts
{
char name[50];
double amount;
};
int main(void)
{
using namespace std;
int things[6] = {13,31,103,301,310,130};
struct debts mr_E[3] =
{
{"Ima Wolfe", 2400},
{"Ura Foxe ", 1300},
{"Iby Stout", 1800}
};
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 <typename T>
void ShowArray(T arr[], int n)
{
using namespace std;
cout << "template A\n";
for (int i = 0; i < n; i++)
cout << arr[i] << ' ';
cout << endl;
}
template <typename T>
void ShowArray(T * arr[], int n)
{
using namespace std;
cout << "template B\n";
for (int i = 0; i < n; i++)
cout << *arr[i] << ' ';
cout endl;
}
cout << endl;
的回复,我最想搞清楚的是重载解析.
①ShowArray<double>(pd, 3);
②cout<<endl;
double * pd[3];
for (int i = 0; i < 3; i++)
pd[i] = &mr_E[i].amount;
//pd没有初始化,就直接使用
ShowArray(pd, 3);
//是这样调用模板函数吗?