为什么提示没有max函数没有被声明

fortuneteller 2018-04-11 09:41:00
编译代码提示错误,提示max函数没有声明,但是已经#include <alogrithm>了。 不理解,请高人指点。


double max_setij_so_far() const {
double max_setij = setij();
std::vector<T*> my_ori = parents();
for (size_t i = 0; i < my_ori.size(); ++i)
max_setij = max(max_setij, my_ori[i]->max_setij_so_far());
return max_setij;
}


错误提示如下
error: ‘max’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
max_setij = max(max_dij, my_parents[i]->max_dij_so_far());

/usr/include/c++/4.8.3/bits/stl_algobase.h:260:5: note: ‘template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ declared here, later in the translation unit
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^

##################
默认的stl_algobase.h 模版我没有修改过 但似乎程序调用系统stl里的max不认识 正常应该可以直接去调用 max(const _Tp& __a, const _Tp& __b)阿,请指点
编译器是gcc 4.8.3

是不是my_ori[i]->max_setij_so_far() 需要重新定义一个量呢
...全文
1043 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
吴瀚 2018-04-12
  • 打赏
  • 举报
回复
using namespace std;
赵4老师 2018-04-11
  • 打赏
  • 举报
回复
__max Returns the larger of two values. type __max( type a, type b ); Routine Required Header Compatibility _max <stdlib.h> Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value __max returns the larger of its arguments. Parameters type Any numeric data type a, b Values of any numeric type to be compared Remarks The __max macro compares two values and returns the value of the larger one. The arguments can be of any numeric data type, signed or unsigned. Both arguments and the return value must be of the same data type. Example /* MINMAX.C */ #include <stdlib.h> #include <stdio.h> void main( void ) { int a = 10; int b = 21; printf( "The larger of %d and %d is %d\n", a, b, __max( a, b ) ); printf( "The smaller of %d and %d is %d\n", a, b, __min( a, b ) ); } Output The larger of 10 and 21 is 21 The smaller of 10 and 21 is 10 Floating-Point Support Routines See Also __min
paschen 版主 2018-04-11
  • 打赏
  • 举报
回复
max是在std名字空间下的 http://en.cppreference.com/w/cpp/algorithm/max
JiMoKuangXiangQu 2018-04-11
  • 打赏
  • 举报
回复
alogrithm 这个没写错吗? algorithm
引用 1 楼 hdt 的回复:
using namespace std; or std::max
+1
真相重于对错 2018-04-11
  • 打赏
  • 举报
回复
using namespace std; or std::max
zilaishuichina 2018-04-11
  • 打赏
  • 举报
回复
std::max<double>
AlbertS 2018-04-11
  • 打赏
  • 举报
回复
using namespace std;

65,176

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧