Why does std::numeric_limitslt;long longgt;::max() fail?(为什么 std::numeric_limitslong long::max() 失败?)
问题描述
这行代码在 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 调用可能会干扰 "evil" 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)();
<小时>
作为附加选项,您可以考虑 #define #NOMINMAX before 包括 Windows 标头.这将阻止上述 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() 失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 std::numeric_limits<long long>::max() 失败?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
