• Advertisement
Sign in to follow this  

Help .... windefs.h is being a bitch!

This topic is 4726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm indirectly including windefs.h in my project. I'm also including limits to gain access to std::numeric_limits< unsigned int >::max(); Unfortunately windefs.h declares a macro also named max, which clashes with the max from limits. I can #undef max so I can use the one from limits, but then the compiler complains that it can't find max later on (apparently the max from windefs.h is needed by many of the Windows headers). Anyone have a good idea? :( P.S. I'm using the Microsoft .NET 2003 C++ compiler.

Share this post


Link to post
Share on other sites
Advertisement
If you are including all of the std:: namespace with using namespace std; then you might want to import just the parts you are interested in with using std::string; and so on.

That way you would be able to either just use std::max whenever you need to use the max from <limits> or have a local code block delimited with curly braces with an using std::max; inside.

Share this post


Link to post
Share on other sites
Hello,

I'm using the numeric_limits thing exactly like I said above, yet the compiler still thinks I'm interested in the macro rather than the template function. I guess macros don't really care about namespaces. :(

Share this post


Link to post
Share on other sites
Alright, I think I've got it solved for now. Had to move some of my includes around a little and use forward declarations to get around having to include certain headers in some places, but overall I'm not really pleased with it.

Share this post


Link to post
Share on other sites
Before #including windows.h you should #define NOMINMAX to avoid the Win32 macros min and max. I believe that this will also avoid problems with other Win32 headers.

Share this post


Link to post
Share on other sites
I just add

#undef min
#undef max

after all my windows code and it sorts it out. Mainly because I didn't know NOMINMAX existed!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement