Re: Cannot use global scope "max" function even ::max is used.
Originally Posted by lucky6969b
Alrite Victor, changed it, but it didn't work, but I've worked around it by #defin'ing it in my header file.
The problem is that the Windows header files defines min() and max() as macros. Attempting to mix them with the C++ standard std::min() and std::max() becomes problematic.
There are two solutions:
1) If your usage of min() and max() are in a CPP file (not a header file), and that source file extensively uses std::min/max, making changes risky, then you should do this:
#include (all of your Windows related headers)
// Your C++ source code
This undefined the macros, includes the C++ header that defines std::min/max. This effectively removes Visual C++'s version from the source module.
2) If you're using std::min/max in a header file, then you can't really use solution 1), since it may mess up other compilation units that may require the macro version of min() and max(). The workaround is to create your own macro/function called mymin()/mymax() (or similar named function), and use that in the header file.