【C++】标准库 std::min/std::max 与 Windows 头文件中的宏 min/max 冲突问题 err
来源:http://www.tudoupe.com时间:2022-06-11
在h的C++源代码中使用std::min/std::max时出现错误。
原因是Windef。 min/max 宏在h 标题文件中定义:
由于在C++标准库之前,Windows头文件中的两个函数的定义出现,所以这不应该是微软的锅。根据上面的定义,如果Windows包含在C++项目.h中,那么,好的建议是 #define NOMINMAX,避免定义min/max,这个宏可以在项目属性中直接定义。
另一种方法是括号 std::min/std::max。
我不完全确定为什么这个方法有效(我没有寻找具体的标准),但我可以简单地说,根据最小/最大的宏观定义,它被定义为函数替换,而不是仅仅是一个标识符替换。
参考:
标准库 std::min/std::max Macro 问题解决 min/max 与 Windows 标题文件冲突 - 跟她一起去 (twofei.(com)
- c++ - std::max - expected an identifier - Stack Overflow
- c++ - How do I deal with the max macro in windows.h colliding with max in std? - Stack Overflow
- c++ - why would I call a function with the function name wrapped in parens? - Stack Overflow
下一篇:CS1.6win10
相关新闻
- 2022-08-04 WPF的由来
- 2022-08-04 Win11勒索软件防护怎么打开?Win11安
- 2022-08-04 Windows系统jdk的配置
- 2022-08-04 Windows10 OneNote怎么重新登录?如何重
- 2022-08-04 超好用的 Windows 效率工具推荐
- 2022-08-04 Windows如何在CMD或PowerShell中配置代理
- 2022-08-04 powershell和cmd对比
- 2022-08-04 【QT】Windows下QT下载安装
- 2022-08-04 windows下 C++ 实现类属性的get和set方
- 2022-08-04 Win11快速助手在哪里?Win11打开快速
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
