Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does std::numeric_limits<long long>::max() fail? [duplicate]

This line of code fails to compile in VS2015 Update 3:

auto a = std::numeric_limits<long long>::max();

It cannot find the definition of max(). Why is this?

like image 632
Sheen Avatar asked Mar 11 '23 17:03

Sheen


1 Answers

That max call may interfere with "evil" max preprocessor macro defined in the Windows SDK headers, that you have probably included (directly or indirectly).

An option is to prevent the preprocessor max macro to kick in, using an additional pair of parentheses:

... = (std::numeric_limits<long long>::max)();

As an additional option, you may consider #define #NOMINMAX before including Windows headers. This will prevent the definition of the aforementioned min and max preprocessor macros.

However, note that some Windows headers (like the GDI+ ones) do require the Win32's min and max preprocessor macros, so in such cases the use of an additional pair of parentheses may be a better option.

like image 85
Mr.C64 Avatar answered Mar 13 '23 05:03

Mr.C64