读书人

小弟我的错?书的错?还是小弟我的编译

发布时间: 2012-02-13 17:20:26 作者: rapoo

我的错?书的错?还是我的编译器的错?
#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分全部奉上!






[解决办法]
vc2005

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

编译没错哦

[解决办法]
g++直接编译过去
[解决办法]
就扔了你的VC6吧,不要浪费生命了。
[解决办法]
things:
Template A
13 31 103 301 310 130 debts:
Template B
2400 1300 1800 Press any key to continue
----------------------------------------------
vc2005

[解决办法]
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.

读书人网 >C++

热点推荐