我的错?书的错?还是我的编译器的错?

clip49 2007-06-08 10:20:02
#include <iostream>
using namespace std;

template <typename T>
void showarr (T arr[] , int n);

template <typename T>
void showarr (T * arr[] , int n);

struct debts
{
char name [50];
double amount;
};

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 << "things: \n";
showarr (things,6);
cout << "debts: \n";
showarr ( pd, 3); //A 处
return 0;
}



template <typename T>
void showarr (T arr[] , int n)
{

cout << "Template A \n";
for(int i = 0 ; i < n ; i++ )
cout << arr[i] << ' ';

}

template <typename T>
void showarr (T * arr[] , int n)
{

cout << "Template B\n";
for ( int i =0 ;i< n; i++)
cout << *arr [i] << ' ';
}
其实 这个是c++ primer Plus 上面的一个例子
我把我的程序和例子对照了 没有出入
但是编译时在A处提示错误 error C2667: 'addarr' : none of 2 overload have a best conversion
是书上面错了么?还是我写错了?还是编译器的问题?
我的是VC++6 SP6
请好心的大大们用30秒拿别的编译器编译一下 看能否通过。
70分全部奉上!




...全文
242 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hu_vane 2007-06-08
  • 打赏
  • 举报
回复
不要用VC6了,那东西对C++标准的支持怎一个差字了得?
wfwd 2007-06-08
  • 打赏
  • 举报
回复
G++吧,学C++就别用VC6了。
yixiao386 2007-06-08
  • 打赏
  • 举报
回复
error C2667: 'showarr' : none of 2 overload have a best conversion
的确如你所说改成showarr<double> ( pd, 3);就编译过去了
再看一下
xuzheng318 2007-06-08
  • 打赏
  • 举报
回复
vs2005看看!
星羽 2007-06-08
  • 打赏
  • 举报
回复
Compiler Error C2667

Language Filter: All Language Filter: Multiple Language Filter: Visual Basic Language Filter: C# Language Filter: C++ Language Filter: J# Language Filter: JScript
Visual Basic (Declaration)
Visual Basic (Usage)
C#
C++
J#
JScript

Error Message
'function' : none of number overloads have a best conversion


An overloaded function call is ambiguous and cannot be resolved.

The conversion required to match the actual parameters in the function call to one of the overloaded functions must be strictly better than the conversions required by all the other overloaded functions.

See Knowledge Base article Q240869 for more information on partial ordering of function templates.

theendname 2007-06-08
  • 打赏
  • 举报
回复
things:
Template A
13 31 103 301 310 130 debts:
Template B
2400 1300 1800 Press any key to continue
----------------------------------------------
vc2005
taodm 2007-06-08
  • 打赏
  • 举报
回复
就扔了你的VC6吧,不要浪费生命了。
  • 打赏
  • 举报
回复
g++直接编译过去
星羽 2007-06-08
  • 打赏
  • 举报
回复
vc2005

1>copyfile - 0 error(s), 6 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

编译没错哦
clip49 2007-06-08
  • 打赏
  • 举报
回复
经过 本人实验
把A处修改成 showarr<double> ( pd, 3);在我可怜的VC6上可以通过
但是根本不是我想要的那样的结果 本来只是一个验证摸板重载和谁更具体化问题
难道这是VC6的弊病?
]就象
string str;
getline(cin.str);
一样么?
clip49 2007-06-08
  • 打赏
  • 举报
回复
对VC6失望了 用起来真不爽!
clip49 2007-06-08
  • 打赏
  • 举报
回复
真想给自己一板砖

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧