vc下一个模板程序的困惑
同一段代码,在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.
#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.
...全文
相关推荐
VC图像模板匹配vc6.0源程序
1 vc6.0编写 2 读写2张bmp图片,并且可以进行模板匹配 3 使用到的算法有MAD算法,NCC算法,快速匹配算法,特征匹配算法 4 仅用于学习
使用VC和MFC创建自定义向导程序
自定义向导程序是一种软件开发工具,它能够引导用户按照预定步骤完成一系列复杂任务。它通常由一系列顺序的页面组成,每个页面集中于特定任务或信息收集点,允许用户进行输入和选择,并且通常包含有状态保存和数据校验功能。向导程序不仅减少了用户在完成任务过程中可能遇到的困惑,还能够在软件安装、配置或用户引导方面提供帮助。自定义向导的主要作用是简化复杂流程。它通过分割复杂任务到一系列小的、易于理解的步骤来减轻用户的认知负担。
一个MFC多文档的小例子vc2015
最近在学习多文档编程,做了一个小例子放这边备查。 里面有做了多模板,创建子窗口,及在窗口上增加控件,不过没有做注释,希望下次还能看得懂。
vc 模板,你所需要的
适用于win32 初始界面的生成。支持vc6.0、vs2010
这是一个基于VC6.0的单文档的OpenGL模板程序。
这是一个基于VC6.0的单文档的OpenGL模板程序。


