6

When I try to compile some code (not my own) i get a C2589 '(':illegal token on right side of'::'

on this line:

    maxPosition[0]=std::numeric_limits<double>::min();

i guess this is because there is already a min() macro defined, but why is the compiler not taking the min() from the specified namespace instead of the macro?

Phil Miller
  • 36,389
  • 13
  • 67
  • 90
Mat
  • 11,263
  • 10
  • 45
  • 48
  • do you have #include ? – matja Dec 01 '09 at 13:28
  • Even though this question is older and I've voted to close as a duplicate of http://stackoverflow.com/questions/1904635, it might be a candidate for merging as the answers there are more comprehensive. –  Feb 22 '10 at 06:56
  • possible duplicate of [warning C4003 and errors C2589 and C2059 on: x = std::numeric\_limits::max();](http://stackoverflow.com/questions/1904635/warning-c4003-and-errors-c2589-and-c2059-on-x-stdnumeric-limitsintmax) – yagni Apr 22 '14 at 20:32

3 Answers3

8

but why is the compiler not taking the min() from the specified namespace instead of the macro?

Because macros don't care about your namespaces, language semantics, or your compiler. The preprocessing happens first.

In other words, the compiler only sees what is left after the preprocessing stage. And min was replaced by some replacement string, and the result is what the compiler saw.

Alex Budovski
  • 17,947
  • 6
  • 53
  • 58
4

Hitting F12 on offending std::numeric_limits::min() function

Leads to some where like :

c:\Program Files (x86)\Windows Kits\8.1\Include\shared\minwindef.h

Where you will find:

#ifndef NOMINMAX

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

So adding

#define NOMINMAX

to top of your .cpp file (as the WINAPI does: see Windows.h as example) before any #include headers should rectify the problem.

bitminer
  • 71
  • 5
0

add this to the top of your file. I'm pretty sure it's just a bug in the way the linker works in Visual studio. You sometimes get this whenever you have an operator overload.

using namespace std;

in my case this works

 for (int i = min(size_used_, other.size_used_) - 1; i >= 0; --i) {
  result += data_[i] * other.data_[i];
}

when this does not

 for (int i = std::min(size_used_, other.size_used_) - 1; i >= 0; --i) {
  result += data_[i] * other.data_[i];
}
steveoams
  • 404
  • 4
  • 6