#define NOMINMAX using std::min/max(#define NOMINMAX 使用 std::min/max)
问题描述
我最近添加了:
#define NOMINMAX
#include <Windows.h>
#include <algorithm>
到我的 main.cpp 以便使用
to my main.cpp in order to use
std::max( x , x ); // x is just a placeholder and not actual anything
std::min( x , x );
但我不能在其他文件中使用 std::max()/std::min().
but i can't use std::max()/std::min() in other files.
error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'
我试图在我的其他文件中添加 #define NOMINMAX,但失败了.什么线索?
i tried to add #define NOMINMAX in my other files, but fails. what is the clue?
我问之前环顾四周,但我不明白答案可能Visual C++ 上 NOMINMAX 的问题
i looked around before asking, but i don't understand the answer Possible problems with NOMINMAX on Visual C++
推荐答案
如果你真的很绝望,请在函数名周围加上括号:
If you're really desperate, put parentheses around the function names:
(std::min)(x, y);
此语法不会应用类似函数的宏.(正式地说,要应用类似函数的宏,宏的名称必须后跟可选的空格,然后是一个 '('.)
This syntax won't apply a function-like macro. (Formally, to apply a function-like macro the name of the macro must be followed by optional white space then a '('.)
这篇关于#define NOMINMAX 使用 std::min/max的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:#define NOMINMAX 使用 std::min/max
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
