Why is std::min failing when windows.h is included?

hidayat picture hidayat · Feb 15, 2011 · Viewed 59.3k times · Source
#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 can't use std::min in visual studio 2005. The error message is:

error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'

Answer

paxdiablo picture paxdiablo · Feb 15, 2011

The windows.h header file (or more correctly, windef.h that it includes in turn) has macros for min and max which are interfering.

You should #define NOMINMAX before including it.