模板重载问题
麻烦各位看一下下面的程序.请多多指点.douboe *pd[3];
//...
Show(pd,3); //为什么不能与下面的Show(T *arr[], int n) 匹配?
//....
.........
template <typename T>
void Show(T *arr[], int n)
{
//....
}
////////////////////////////////////////////////////////
完整的程序如下:
#include <iostream>
using namespace std;
template <typename T>
void Show(T arr[], int n);
template <typename T>
void Show(T *arr[], int n);
struct debts
{
char name[50];
double amount;
};
int main(void)
{
int things[6]={301,302,303,304,305,306};
struct debts debtsArr[3]=
{
{"Micheal Zhuang",2500.0},
{"Echo She",2600.0},
{"James He",2300.0}
};
double *pd[3];
for(int i=0; i<3; i++)
pd[i]=&debtsArr[i].amount;
Show(things,6);
cout << "Count infomation:\n";
Show(pd,3);
return 0;
}
template <typename T>
void Show(T arr[], int n)
{
cout << "Using template A:\n";
for(int i=0; i<n; i++)
cout << arr[i] << " ";
cout << endl;
}
template <typename T>
void Show(T *arr[], int n)
{
cout << "Using template B:\n";
for(int i=0; i<n; i++)
cout << *arr[i] << " ";
cout << endl;
}