Conflict windows.h and limits?

The following code does not work in VS2010. What is the reason?

#include <limits> #include <windows.h> // if I remove this line, it is okay. int main() { std::numeric_limits<int>::min(); return 0; } 

I created an empty VC console project and add main.cpp as above. This is the reason? Can I create another project? Thanks.

Thanks for helping your guys. The problem arises because I use vld.h and limits together. I read vld.h to try and find the problem myself. After some testing, I found that the problem could be related to window.h , which includes vld.h Sorry to forget about Google. And I personally think that stackoverflow is very useful for your guys, kind help for new programmers, like me.

+6
source share
2 answers

This is a known issue caused by the failed max macro defined in windows.h (actually, windef.h enabled by windows.h , to be more precise). Determining NOMINMAX before enabling windows.h should fix the problem. For instance:

 #define NOMINMAX #include <windows.h> 
+14
source

Sometimes #define NOMINMAX does not work (I see such examples), then you can always #undef MIN and #undef MAX .

In addition, since you are using VS2010, it is generally recommended that you use such preprocessor workarounds for windows in stdafx.h and do not repeat them all the time.

+3
source

All Articles