Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

c++ - #define NOMINMAX using std::min/max

i recently added:

#define NOMINMAX
#include <Windows.h>
#include <algorithm>

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 );

but i can't use std::max()/std::min() in other files.

error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'

i tried to add #define NOMINMAX in my other files, but fails. what is the clue?

i looked around before asking, but i don't understand the answer Possible problems with NOMINMAX on Visual C++

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...