为什么std :: numeric_limits< long long> :: max()失败? [英] Why does std::numeric_limits<long long>::max() fail?
问题描述
此行代码无法在VS2015 Update 3中编译:
This line of code fails to compile in VS2015 Update 3:
auto a = std::numeric_limits<long long>::max();
找不到 max()
的定义.为什么会这样?
It cannot find the definition of max()
. Why is this?
推荐答案
max
调用可能会干扰邪恶的" max
预处理器宏Windows SDK标头中定义的内容,您可能已经包含了这些内容(直接或间接).
That max
call may interfere with "evil" max
preprocessor macro defined in the Windows SDK headers, that you have probably included (directly or indirectly).
一种选择是使用一对额外的括号来阻止预处理器 max
宏出现:
An option is to prevent the preprocessor max
macro to kick in, using an additional pair of parentheses:
... = (std::numeric_limits<long long>::max)();
作为附加选项,您可以考虑在包含Windows标头的 #define #NOMINMAX
之前.这将阻止定义上述 min
和 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.
但是,请注意,某些Windows标头(例如GDI +标头)确实需要Win32的 min
和 max
预处理程序宏,因此在在这种情况下,最好再加上一对括号.
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.
这篇关于为什么std :: numeric_limits< long long> :: max()失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!