Min or max error in C++


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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.