问题描述
我遇到了 std :: max
的问题。我不能想出来。
int border = 35;
int myInt = 2;
int myOtherInt = 3;
int z = std :: max(myInt + 2 * border,myOtherInt + 2 * border);
我已包含算法标准标题。当我鼠标超过max时,我得到:
编译错误:
有什么问题?
危害猜测,因为你使用VC ++–把这个放在任何 #include
s:
#define NOMINMAX
windows.h
定义名为 min
和 max
例如:
#define min(a,b)(((a)<(b))? :(b))
pre>
#define max(a,b)(((a)>(b))?(a):(b))
Windows SDK包含了这些宏,因为C ++标准化之前,但是因为它们明显对C ++标准库造成破坏,所以可以定义
通常,如果您使用C ++(而不是C),并且包括
windows.h
,始终首先定义NOMINMAX
。I'm having a problem with
std::max
. I can't figure it out.int border = 35; int myInt = 2; int myOtherInt = 3; int z = std::max(myInt + 2 * border, myOtherInt + 2 * border);
I've included the algorithm standard header. When I mouse over max, I am getting:
And a compile errors of:
What is wrong?
解决方案Hazarding a guess, since you're using VC++ – put this before any
#include
s:#define NOMINMAX
windows.h
defines macros namedmin
andmax
like so:#define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b))
The Windows SDK has contained these macros since before C++ was standardized, but because they obviously play havoc with the C++ standard library, one can define the
NOMINMAX
macro to prevent them from being defined.As a rule, if you're using C++ (as opposed to C) and including
windows.h
, always defineNOMINMAX
first.这篇关于std :: max - 期望一个标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!