#define NOMINMAX using std::min/max

后端 未结 4 1051
春和景丽
春和景丽 2020-11-27 05:39

i recently added:

#define NOMINMAX
#include 
#include 

to my main.cpp in order to use

st         


        
4条回答
  •  一整个雨季
    2020-11-27 06:17

    It's likely that your problem is that you #define NOMINMAX after you #include "windows.h". It is important that the #define come first.

    The reason is that windows.h (actually I think windef.h, which is included by windows.h) has code similar to this:

    #ifndef NOMINMAX
    #define min(x,y) ((x) < (y) ? (x) : (y))
    #define max(x,y) ((x) > (y) ? (x) : (y))
    #endif
    

    So #define NOMINMAX is telling the compiler (or actually the preprocessor) to skip over the definitions of min and max, but it will only apply if you do it before you #include "windows.h".

提交回复
热议问题