std::min() compiler error with WIN32

Hi All:

I'm no beginner, but I must be making a beginner's mistake.

Building the app on Win 8.1 Pro, Visual Studio 2010.

The following WIN32 code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
#include <windows.h>
#include <iostream>
#include <algorithm>

int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                            PSTR szCmdLine, int iCmdShow)
{
    int a = 1;
    int b = 2;
    int c = 0;

    c = std::min(a, b);
}


Gets these compiler errors:

1>ClCompile:
1> min_win32.cpp
1>e:\...\min_win32.cpp(12): error C2589: '(' : illegal token on right side of '::'
1>e:\...\min_win32.cpp(12): error C2059: syntax error : '::'
1>
1>Build FAILED.

I create a console project, which uses main() instead of WinMain():

1
2
3
4
5
6
7
8
9
10
11
12
13
 
#include <iostream>
#include <algorithm>

int main()
{
    int a = 1;
    int b = 2;
    int c = 0;

    c = std::min(a, b);
}


This code compiles and runs fine.

I write WIN32 C++ programs for a living. Just now I compiled an app that has almost 50 calls std::min() with no errors.

I'm trying to track down a problem unrelated to std::min() by building a simple app to show to a forum, but I can't get that to work because my call to std::min() has this error.

What am I doing wrong?

Thanks
Larry
Last edited on
see if this helps

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define NOMINMAX
#include <windows.h>
#include <iostream>
#include <algorithm>

int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                            PSTR szCmdLine, int iCmdShow)
{
    int a = 1;
    int b = 2;
    int c = 0;

    c = std::min(a, b);
}
Thanks Yanson:

That works.

I did a search for "NOMINMAX" in several applications that use std::min() and found nothing in the source, headers or the preprocessor parameters.

I wonder why these two small pieces of sample code require it.

Thanks
Larry
Topic archived. No new replies allowed.