How do I call std::min
when min
has already been defined as a macro?
You might be able to avoid the macro definition by:
#undef
#define NOMINMAX
or similar or avoiding including the offending header)If those options can't be used or you don't want to use them, you can always avoid invoking a function-like macro with an appropriate use of parens:
#include
#include
#define min(x,y) (((x) < (y)) ? (x) : (y))
int main()
{
printf( "min is %d\n", (std::min)( 3, 5)); // note: the macro version of `min` is avoided
}
This is portable and has worked since the dark, early days of C.