Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't call std::max because minwindef.h defines "max" [duplicate]

Tags:

c++

std

macros

How would I go about actually calling std::max? The code won't compile in visual studio 2013, because it takes "max" as the macro.

std::max( ... );

Expects an identifier after the "std::".

like image 685
Ben Avatar asked Mar 30 '14 12:03

Ben


1 Answers

You can undefine the macro:

#undef max

Edit: It seems the macros can be safely disabled by putting

#define NOMINMAX

before the header files that define them (most likely windef.h, which you probably include indirectly).

To avoid undefining the macro, you can simply wrap the function in parenthesis

(std::max)(...)

As noted by chris in the comments, function-like macros require the token after the macro name to be a left parenthesis in order to expand. Wrapping the name in parentheses is really just a hack to make the next token a right parenthesis without changing the meaning once you put macros aside.

like image 132
juanchopanza Avatar answered Sep 20 '22 16:09

juanchopanza