首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于模板重载的有关问题

2012-02-09 
关于模板重载的问题我的程序是:#include iostreamtemplatetypenameTvoidShowArray(Tarr[],intn)templ

关于模板重载的问题
我的程序是:
#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()
{
using   namespace   std;
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   <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;
}
编译的时候报错:

E:\vc++   6.0\MSDev98\MyProjects\test3\8_14.cpp(29)   :   error   C2667:   'ShowArray '   :   none   of   2   overload   have   a   best   conversion
E:\vc++   6.0\MSDev98\MyProjects\test3\8_14.cpp(29)   :   error   C2668:   'ShowArray '   :   ambiguous   call   to   overloaded   function
Error   executing   cl.exe.
我用的是vc++6.0,怎么回这样?

[解决办法]
错就错在你不该用vc6

换成vc2005,或者g++ 4
vc对这个那是无能为力的
[解决办法]
vc6对C99支持不够好
而且bug较多
[解决办法]
扔了VC6吧。
[解决办法]
楼上已经说了.

热点排行