The compiler "forces" me to use the std::max method,
I cannot override it even when writing ::max in my code.
Any ideas would be nice.
Thanks
Jack
Printable View
The compiler "forces" me to use the std::max method,
I cannot override it even when writing ::max in my code.
Any ideas would be nice.
Thanks
Jack
The simplest way would to removeand add std:: prefix to all functions from std library.Code:using namespace std;
See also http://stackoverflow.com/questions/1...-practice-in-c
Alrite Victor, changed it, but it didn't work, but I've worked around it by #defin'ing it in my header file.
Thanks
Jack
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:
This undefined the macros, includes the C++ header that defines std::min/max. This effectively removes Visual C++'s version from the source module.Code:#include (all of your Windows related headers)
#undef min
#undef max
#include <algorithm>
//...
// Your C++ source code
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.
Regards,
Paul McKenzie
Do not write any macro named min() and max() in a header file. Not only is there no need to, but it is very risky to do so. You're risking having modules not compile correctly.
Instead, work with what exists. Either you #undef the existing macros in a CPP source file and use std::min()/max(), or create brand new functions named differently than min() and max().
Regards,
Paul McKenzie