Use of min () and max () functions in Visual C ++

Source: Internet
Author: User

The standard library defines two template functions in the <algorithm> header: STD: min () and STD: max (). It is usually used to calculate the minimum and maximum values of a value pair.

Unfortunately, they cannot be used in Visual C ++ because these function templates are not defined. The reason is that the name Min and Max conflict with the traditional min/MAX macro definition in <windows. h>. To solve this problem, Visual C ++ defines two templates with the same functions: _ cpp_min () and _ cpp_max (). We can use them to replace STD: min () and STD: max ().

To disable the min/MAX macro definition in Visual C ++, you can add:
# Define nominmax
Or add nominmax to Preprocessor difinitions. The specific method is:

Visual c ++ 6.0: Open the project file (*. DSW) or (*. DSP), select the project to be defined, and go to the menu "project" => "Settings" (open the Settings dialog box) => in the "setting for" drop-down list box in the upper left corner, select "all deployments ", then select the "C/C ++" label => Add "nominmax" to the "Preprocessor difinitions" edit box.

Visual c ++ 7.0: Open the project file (*. SLN) or (*. vcproj), select the project to be defined, and go to the menu "project" => "properties" (open the Project Properties dialog box) => in the "configuration" drop-down list box in the upper left corner, select "All configurations ", then, select "C/C ++"> "pre-processor"> "pre-processor definition" on the left and add "nominmax ".

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.