Use of the Min () and Max () functions in Visual C + +

Source: Internet
Author: User

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

Unfortunately, they are not available in Visual C + + because these function templates are not defined. The reason is that the name min and Max are in conflict with the traditional Min/max macro definition in <windows.h>. To solve this problem, Visual C + + defines two other templates with the same functionality: _cpp_min () and _cpp_max (). We can use them instead of std::min () and Std::max ().

In order to disable the Min/max macro definition in Visual C + +, you can include the <windows.h> header file by adding:


Or add Nominmax to the preprocessor difinitions. The specific methods are:

Visual C + + 6.0: Open a project file (*.DSW) or (*.DSP), select the project you want to define, go to the menu "project" and "Settings" (Open Settings dialog box) and "Setting for" in the upper left corner Drop-down list box, select "All Configurations", and then select the "C + +" tab and "Add Nominmax" to the "Preprocessor difinitions" edit box.

Visual C + + 7.0: Open the Project document (*.sln) or (*.vcproj), select the project to be defined, go to the menu "project" and "Properties" (Open Project Properties dialog box) and select "All Configurations" at the top left of the "Configuration" drop-down list box. Then in the left "property configuration", select "+/C + +" and "preprocessor" +-right "preprocessor definition" plus "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.