vc下一个模板程序的困惑

westdo 2005-08-10 05:25:52
同一段代码,在gcc中编译通过,并且能正常执行,但是到了vc下报错.请各位弟兄帮忙.代码如下

#include <iostream>
using namespace std;

template <class Type,int size> Type min(Type (&r_array)[size])
{
Type min_val=r_array[0];
for(int i=1;i<size;++i)
{
if(r_array[i]<min_val)
min_val=r_array[i];
}
return min_val;
}
int ia[]={10,6,7,3,23};
double da[]={10.2,7.1,14.5,3.2,25.0,16.8};

int main()
{


int i=min(ia);
if(i!=3)
cout<<"failed!"<<endl;
else
cout<<"ok!"<<endl;

double d=min(da);
if(d!=3.2)
cout<<"failed!"<<endl;
else
cout<<"ok!"<<endl;

return 0;
}
编译的时候报错
min.cpp
E:\ctest\min.cpp(4) : error C2265: '<Unknown>' : reference to a zero-sized array is illegal
E:\ctest\min.cpp(34) : error C2784: 'Type __cdecl min(Type (&)[1])' : could not deduce template argument for ' (&)[1]' from 'int [5]'
E:\ctest\min.cpp(40) : error C2784: 'Type __cdecl min(Type (&)[1])' : could not deduce template argument for ' (&)[1]' from 'double [6]'
Error executing cl.exe.
...全文
142 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qhfu 2005-08-10
  • 打赏
  • 举报
回复
是vc6.0不支持吧! vs2003下运行很正常 呵呵! 
healer_kx 2005-08-10
  • 打赏
  • 举报
回复
给分吧。。。VC是不支持的。

64,282

社区成员

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

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