問題描述
我最近添加了:
#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?
我問之前環(huán)顧四周,但我不明白答案可能Visual C++ 上 NOMINMAX 的問題
i looked around before asking, but i don't understand the answer Possible problems with NOMINMAX on Visual C++
推薦答案
如果你真的很絕望,請(qǐng)?jiān)诤瘮?shù)名周圍加上括號(hào):
If you're really desperate, put parentheses around the function names:
(std::min)(x, y);
此語法不會(huì)應(yīng)用類似函數(shù)的宏.(正式地說,要應(yīng)用類似函數(shù)的宏,宏的名稱必須后跟可選的空格,然后是一個(gè) '('.)
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 '('.)
這篇關(guān)于#define NOMINMAX 使用 std::min/max的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!