VC6.0不支持标准库函数max和min

今天写程序时在VC6.0中用到了函数max()和min()来求最大值和最小值,结果发现VC6.0不支持这两个函数,这应该是vc的问题吧,连标准库函数都不支持,不过这也正常,毕竟VC6.0不支持C++标准。本人自己写了这两个函数,C++标准库是这样实现的,所以可以当作库函数使用。
max()和min()函数的实现如下:
InBlock.giftemplate< class T,  class Compare>
InBlock.gifinline  const T& max( const T& a,  const T& b, Compare comp) 
InBlock.gif{
InBlock.gif   return comp(a, b) ? b : a;
InBlock.gif}
InBlock.gif
  template< class T,  class Compare>
InBlock.gifinline  const T& min( const T& a,  const T& b, Compare comp)
InBlock.gif{
InBlock.gif   return comp(b, a) ? b : a;
InBlock.gif}
使用方式如下:
InBlock.gif bool int_less( int a,  int b)
InBlock.gif{
InBlock.gif   return a < b;
InBlock.gif}
InBlock.gif int main()
InBlock.gif{
InBlock.gif   int a = 10;
InBlock.gif   int b = 20;
InBlock.gif   int result;
InBlock.gif  result = max(a, b, int_less);
InBlock.gif  cout <<  "max(a, b): " << result << endl;
InBlock.gif  result = min(a, b, int_less);
InBlock.gif  cout <<  "min(a, b): " << result << endl;
InBlock.gif   return 0;
InBlock.gif}




     本文转自panpan3210 51CTO博客,原文链接:http://blog.51cto.com/panpan/103074 ,如需转载请自行联系原作者


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值