代码

#include<iostream>
#include <algorithm> // std::min
#undef min
int main()
{
float a =15.0f;
float c ;
c=std::min(10,a);
printf("%f",b);
getchar();
}

错误提示

Error 1 error C2780: 'const _Ty &std::min(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided 
Error 2 error C2782: 'const _Ty &std::min(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous
3 IntelliSense: no instance of overloaded function "std::min" matches the argument list
4 IntelliSense: too few arguments in function call

unction template (C++98)

template <class T> const T& min (const T& a, const T& b) {
  return !(b<a)?a:b;     // or: return !comp(b,a)?a:b; for version (2)
}
错误分析
min采用的stl模板,算法的原型中,a,b两个形参应该为相同类型,c=std::min(10,a); 10 与 a 的类型不匹配导致了一下的错误

修改方法
方法1
c=std::min(10.0f,a);
方法2
float b=10;
c=std::min(b,a);
方法3
c=std::min((float)10.0,a);

 

 

相关文章:

  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
猜你喜欢
  • 2022-12-23
  • 2021-11-04
  • 2021-06-03
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案