一个有关vc6++与dev-c++编译环境的问题

kfjin 2003-11-24 03:17:52
#include <iostream>
using namespace std;

template <class Type>
Type min( Type a, Type b ){ return a < b ? a : b; }

const int size = 10;
int ia[size];

int main()
{
int *p = &ia[ 0 ];
int elem_cnt = 0;
while ( min(p++,&ia[size]) != &ia[size] )
++elem_cnt;

cout << "size is " << size << endl
<< "elem_cnt is " << elem_cnt << endl;
system("PAUSE");
return 0;
}

上述程序在VC6++环境下可编译通过,但在dev-c++中确不能通过,

提示出错语句为:
while ( min(p++,&ia[size]) != &ia[size] )

出错原因为:
call of overloaded `min(int*, int*)' is ambiguous

为何呢,为何会出现二义性?
请回答,谢谢!
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kfjin 2003-11-26
  • 打赏
  • 举报
回复
谢谢“liem”,是不是说dev-cpp已经有min这个模板啦?

ok!我把“min”替换成 “aa”后,就可以在dev-c++环境下通过啦,看来还是因为书写得不规范引起的。
再次谢谢!
liem 2003-11-25
  • 打赏
  • 举报
回复
根据在DEVCPP上编译时出错信息提示,发现在DEVC++中已经有min模板:
d:\Dev-Cpp\include\c++\bits\stl_algobase.h:、

template<typename _Tp>
inline const _Tp&
min(const _Tp& __a, const _Tp& __b)
{
// concept requirements
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>)
//return __b < __a ? __b : __a;
if (__b < __a) return __b; return __a;
}

二义性从此而来的。
kfjin 2003-11-25
  • 打赏
  • 举报
回复
up

64,685

社区成员

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

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