Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

Error: expected an identifier

And a compile errors of:

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

What is wrong?

See Question&Answers more detail:os

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

1 Answer

Hazarding a guess, since you're using VC++ – put this before any #includes:

#define NOMINMAX

windows.h defines macros named min and max 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 define NOMINMAX first.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...