macro and member function conflict

The workaround is to use the parenthesis: int max = (std::numeric_limits<int>::max)();

It allows you to include the windef.h, doesn't require you to #undef max (which may have adverse side effects) and there is no need to #define NOMINMAX. Works like a charm!


The only really general solution is to not include windows.h in your headers.

That header is a killer, and does pretty much anything it can to make your code blow up. It won't compile without MSVC language extensions enabled, and it is the worst example of macro abuse I've ever seen.

Include it in a single .cpp file, and then expose wrappers in a header, which the rest of your code can use. If windows.h isn't visible, it can't conflict with your names.

For the min/max case specifically, you can #define NOMINMAX before including windows.h. It will then not define those specific macros.

Tags:

C++