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?
numeric_limits::minReturns the minimum finite value representable by the numeric type T . For floating-point types with denormalization, min returns the minimum positive normalized value. Note that this behavior may be unexpected, especially when compared to the behavior of min for integral types.
The std::numeric_limits ::digits function is used to find the number of radix digits that the data type can represent without loss of precision.
std::numeric_limits::max(): The std::numeric_limits<T>::max() function is used to get the maximum finite value representable by the numeric type T. All arithmetic types are valid for type T. Header File: #include<limits>
Data types that supports std::numeric_limits() in C++ std::numeric_limits<int>::max() gives the maximum possible value we can store in type int. std::numeric_limits<unsigned int>::max()) gives the maximum possible value we can store in type unsigned int.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With