msh msh - 1 year ago 163
C++ Question

macro and member function conflict

I have problem that,std::numeric_limits::min() conflicts with the "min" macro defined in "windef.h". Is there any way to resolve this conflict without undefine the "min" macro.
The link below gives some hints, however I couldn't manage to use parenthesis with a static member function.

What are some tricks I can use with macros?

Thank you in advance.

Answer Source

The workaround is to use the parenthesis: int max = (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 NONIMAX. Works like a charm!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download