hidayat hidayat - 1 year ago 96
C++ Question

std::min gives error

#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 : '::'

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download