C++出现“max”: 对重载函数的调用不明确

2025年03月19日 06:33
有3个网友回答
网友(1):

c++本身已经定义了一个max函数。所以你试试下面这牙膏你就知道了
#include
using namespace std;
template
T my_max(T x,T y)
{
return x>y?x:y;
}
/*int max(int x,int y)
{
return x>y?x:y;
}
float max(float c,float d)
{
return c>d?c:d;
}*/
int main()
{
int a,b;
float m,n;
cin>>a>>b>>m>>n;
cout<<"a="< cout<<"b="< cout<<"m="< cout<<"n="< cout<<"The max is "< cout<<"The max is "<}

网友(2):

貌似是std里已经有max这个函数了,所以可以改成::max();

网友(3):

考虑是不是因为赋值兼容导致的?也就是max(a,b)系统不知道调用哪一个?你把类定义里面的int型的删掉试试