Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Min or max error in C++

📅 2015-Oct-26 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ error, max, min ⬩ 📚 Archive


C++ code using the std::min and std::max can fail with a cryptic error message when compiled with Visual Studio on Windows:

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


This is caused if you are including windows.h. That header defines these as old-style macros.

To indicate that these macros not be defined, define NOMINMAX before including that header:

#define NOMINMAX
#include <windows.h>

Tried with: Visual Studio 2015 and Windows 7 x64

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧