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

半腔热情 提交于 2021-02-04 07:21:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40492414/why-does-stdnumeric-limitslong-longmax-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!