#使用std :: min/max定义NOMINMAX [英] #define NOMINMAX using std::min/max

查看:245
本文介绍了#使用std :: min/max定义NOMINMAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近添加了:

#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 '('.)

这篇关于#使用std :: min/max定义NOMINMAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆