Discussion:
min : is not a member of std
(too old to reply)
Steve Pole
2004-05-06 19:08:15 UTC
Permalink
Hi all,

I am entirely puzzled. I have the following trivial code in a header file:

#include <algorithm>
using std::min;

Visual C++ 6.0 SP4 says

error C2039: 'min' : is not a member of 'std'

followed by

error C2873: 'min' : symbol cannot be used in a using-declaration.

I am not even using std::min yet. The application uses the Trolltech Qt
library v2.3.0, but I actually doubt that this is the cause.

Yes, I have read the "Using std::max bug" thread attentively and I also
know about http://support.microsoft.com/?id=143208. I have tried adding
#define NOMINMAX of #undef min, but to no avail.

The actually puzzling aspect is that I have identical code in the
prototype application which builds fine there - on the same system, with
the same libraries, with the same compiler. I have reproduced the
problem on a second machine.

I am about to use brute force and start 'aligning' the settings in both
.dsp projects until they are identical or until I find the root of the
problem, but these are pretty big projects, so I would be happy about
any other solution...


I'm starting to feel like I'm staring at it, but I just can't see it....


Does someone know what I'm doing wrong ?


CU S>
Igor Tandetnik
2004-05-06 19:42:51 UTC
Permalink
Post by Steve Pole
error C2039: 'min' : is not a member of 'std'
See http://babbage.cs.qc.edu/STL_Docs/algorithm_min.htm . To avoid
conflicts with min and max macros, the functions in <algorithm> are
named _cpp_min and _cpp_max. Further, a macro _MIN expands to _cpp_min
and _MAX to _cpp_max.

The problem is fixed in VC7.1, where the algorithms are named min and
max, as they should. See also

http://msdn.microsoft.com/library/en-us/vccore/html/vclrfminmaxdefinechange.asp
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
red floyd
2004-05-07 16:49:15 UTC
Permalink
Post by Igor Tandetnik
Post by Steve Pole
error C2039: 'min' : is not a member of 'std'
See http://babbage.cs.qc.edu/STL_Docs/algorithm_min.htm . To avoid
conflicts with min and max macros, the functions in <algorithm> are
named _cpp_min and _cpp_max. Further, a macro _MIN expands to _cpp_min
and _MAX to _cpp_max.
The problem is fixed in VC7.1, where the algorithms are named min and
max, as they should. See also
http://msdn.microsoft.com/library/en-us/vccore/html/vclrfminmaxdefinechange.asp
The OP might also want to look at #define NOMINMAX before including
windows.h
Carl Daniel [VC++ MVP]
2004-05-07 17:57:37 UTC
Permalink
Post by red floyd
The OP might also want to look at #define NOMINMAX before including
windows.h
If you read the OP, you'll see that he already tried that. As Igor pointed
out, std::min and std::max simply don't exist in the VC6 version of STL,
regardless of what macros are defined or not.

-cd
Matt Osborn
2004-05-07 20:16:56 UTC
Permalink
Post by Carl Daniel [VC++ MVP]
Post by red floyd
The OP might also want to look at #define NOMINMAX before including
windows.h
If you read the OP, you'll see that he already tried that. As Igor pointed
out, std::min and std::max simply don't exist in the VC6 version of STL,
regardless of what macros are defined or not.
Nevertheless, we must still #define NOMINMAX before including windows.h.
This causes untold difficulties when headers that we cannot modify do not
#define NOMINMAX. I think Microsoft ought to eliminate the MIN/MAX/min/max
macros entirely.
Our solution has been to create new templates for min_ and max_, but that
still leaves us SOL with numeric_limits<>::max ()
Carl Daniel [VC++ MVP]
2004-05-07 23:39:27 UTC
Permalink
Post by Matt Osborn
Nevertheless, we must still #define NOMINMAX before including
windows.h. This causes untold difficulties when headers that we
cannot modify do not #define NOMINMAX. I think Microsoft ought to
eliminate the MIN/MAX/min/max macros entirely.
Our solution has been to create new templates for min_ and max_, but
that still leaves us SOL with numeric_limits<>::max ()
Absolutely so! The min & max macros are pure solid evil and NOMINMAX is an
essential tool - it just doesn't help with the OP's problem.

The problem with getting rid of the macros is that <windows.h> and
everything it includes belongs to the Windows team, not the Visual Studio
team, and the Win32 API is a C API, not C++.

I think having VC++ automatically #define NOMINMAX in newly created projects
would be a fine addition though!

-cd
red floyd
2004-05-11 18:02:34 UTC
Permalink
I suspect it has to do with #defines of min and max.

I'd try #defining NOMINMAX before including windows.h (best bet is in stdafx.h)
Post by Steve Pole
Hi all,
#include <algorithm>
using std::min;
Visual C++ 6.0 SP4 says
error C2039: 'min' : is not a member of 'std'
followed by
error C2873: 'min' : symbol cannot be used in a using-declaration.
I am not even using std::min yet. The application uses the Trolltech Qt
library v2.3.0, but I actually doubt that this is the cause.
Yes, I have read the "Using std::max bug" thread attentively and I also
know about http://support.microsoft.com/?id=143208. I have tried adding
#define NOMINMAX of #undef min, but to no avail.
The actually puzzling aspect is that I have identical code in the
prototype application which builds fine there - on the same system, with
the same libraries, with the same compiler. I have reproduced the
problem on a second machine.
I am about to use brute force and start 'aligning' the settings in both
.dsp projects until they are identical or until I find the root of the
problem, but these are pretty big projects, so I would be happy about
any other solution...
I'm starting to feel like I'm staring at it, but I just can't see it....
Does someone know what I'm doing wrong ?
CU S>
red floyd
2004-05-13 15:37:38 UTC
Permalink
[redacted]
whoops! Apparently VC6 is evil. There was discussion on another thread.
Steve Pole
2004-05-27 23:01:27 UTC
Permalink
Post by Steve Pole
Hi all,
...
CU S>
Hi everyone,

thank you very much for your expert help.

I solved the problem by including a few headers from the boost library
(www.boost.org) I needed anyway for something else. I don't exactly know
what they do, but they have solved the problem somehow.


Regards from my roof patio ;-)


CU S>

Continue reading on narkive:
Loading...