#include <algorithm>
#include <Windows.h>
int main()
{
int k = std::min(3, 4);
return 0;
}
What is windows doing, if I include Windows.h I cant use std::min in visual studio 2005. The error message is:
error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'
is the trick to suppress the macro definitions of max and min
http://support.microsoft.com/kb/143208
No need to define anything, just bypass the macro using this syntax:
As others mentioned, the errors are due to min/max macros that are defined in windows header(s). There are three ways of disabling them.
1)
#define NOMINMAX
before including header, this is generally a bad technique of defining macros in order to affect the following headers;2) define
NOMINMAX
in compiler command line/IDE. The bad part about this decision is that if you want to ship your sources, you need to warn the users to do the same;3) simply undefine the macros in your code before they are used
This is probably the most portable and flexible solution.
In my case, project did not include
windows.h
orwindef.h
explicitly. It was using Boost. So, I resolved the issue by going to the projectProperties -> C/C++ -> Preprocessor
, and appendingNOMINMAX
in thePreprocessor Definitions
(VS 2013, VS 2015).