模板不能用dev c++编译

Templates do not compile with dev c++

本文关键字:c++ 编译 dev 不能      更新时间:2023-10-16
#include<conio.h>
#include<iostream>
using namespace std;
template<class T>
T min(T a,T b)
{
return (a>b)?a:b;
}
int main()
{
int x,y;
cin>>x>>y;
cout<<"min. of integer value is="<<min(x,y); //error is call of overloaded function    is ambiguous.
float p,q;
cin>>p>>q;
cout<<"min. of floating value is="<<min(p,q);//same error as above
char c1,c2;
cin>>c1>>c2;
cout<<"min. of c1 and c2(basis of ASCII values)="<<min(c1,c2);// same error as    above
getch();
return 0; }

是否有任何内置功能的dev c++不支持模板或有一些其他的错误?

原因是存在一个std::min,它被导入到全局命名空间中(由于using namespace std;)。

所以你有两个不同版本的min:你的版本(实际上返回最大值…),和标准的最小值。

重命名你的最小函数,或者删除它(并使用std::min代替)。