About the use of the Max (A, B) and Min (A, B) functions

Source: Internet
Author: User
Tags min

About the use of the Max (A, B) and Min (A, B) functions in VS2013

These two functions in the header file <algorithm> will return a and B in the smaller/larger one.

Can not be changed to _min and _max. Check that you can replace this in Windows engineering

Website: https://zhidao.baidu.com/question/135498020.html

For the use of Linux and VC6, copy the answer to a post in CSDN

First, Max () is really a function rather than a macro in standard C + +. It is actually defined in different compilation systems as follows:
===========================================================
Linux g++, header files <algorithm>
Template <class _tp>
Inline const _tp& MAX (const _tp& __a, const _tp& __b) {
Return __a < __b? __b: __a;
}
===========================================================
VC6 under Windows, header file <algorithm> (latest vs.net not tried, dare not to be raved)
Template<class _ty> Inline
Const _ty& _cpp_max (const _ty& _x, const _ty& _y)
{return (_x < _y _y: _x);}
===========================================================

Did you see it? g++ defined it as Max () according to standard C + +, and VC6 made it into a _cpp_max ().
In fact, the source code I attached to my question was in accordance with the standard C + + rules and was compiled successfully under g++, and because VC6 changed Max () to _cpp_max (), it failed to compile.

To use Max () in VC6, you can only retreat to the second using _cpp_max (). or _max ().
Because in the header file algorithm contains another header file xutility There is a sentence #define _max _cpp_max

There is also a related macro __max, which is defined in Stdlib.h: #define __MAX (A, B) (((a) > (a))? (a): (b)), but __max is not standard C + +, which was left by the previous C.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.