首页 > 其他 > 详细

std::min 与std::max 的 Compiler Error C2780

时间:2014-09-21 19:01:52      阅读:218      评论:0      收藏:0      [点我收藏+]

代码

#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);

 

 

std::min 与std::max 的 Compiler Error C2780

原文:http://www.cnblogs.com/sheshouyanhun/p/3984825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!