warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits<int>::max();
This commonly occurs when including a Windows header that defines a min
or max
macro. If you're using Windows headers, put #define NOMINMAX
in your code, or build with the equivalent compiler switch (i.e. use /DNOMINMAX for Visual Studio).
Note that building with NOMINMAX
disables use of the macro in your entire program. If you need to use the min
or max
operations, use std::min()
or std::max()
from the <algorithm>
header.
warning C4003: not enough actual parameters for macro 'max' - Visual Studio 2010 C++
Add #undef max
to the top of the relevant files.
PCL1.7.2 in QT5.4.1 --- error: C2589, C2059, C2181 in PCL header file
Those error codes are quite often related to the Windows issue warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits<int>::max();
Indeed there is std::numeric_limits<>::max()
in io_operators.h:66
and pcl_io.h:281
.
So, if it is the only problem it can be fixed by changing order of headers by moving pcl
headers on top to avoid including windows.h
(that may be included from some other header) before or by defining NOMINMAX
before all inclusions.
Syntax error with std::numeric_limits::max
Your problem is caused by the <Windows.h>
header file that includes macro definitions named max
and min
:
#define max(a,b) (((a) > (b)) ? (a) : (b))
Seeing this definition, the preprocessor replaces the max
identifier in the expression:
std::numeric_limits<size_t>::max()
by the macro definition, eventually leading to invalid syntax:
std::numeric_limits<size_t>::(((a) > (b)) ? (a) : (b))
reported in the compiler error: '(' : illegal token on right side of '::'
.
As a workaround, you can add the NOMINMAX
define to compiler flags (or to the translation unit, before including the header):
#define NOMINMAX
or wrap the call to max
with parenthesis, which prevents the macro expansion:
size_t maxValue_ = (std::numeric_limits<size_t>::max)()
// ^ ^
or #undef max
before calling numeric_limits<size_t>::max()
:
#undef max
...
size_t maxValue_ = std::numeric_limits<size_t>::max()
In c++, is it safe to use std::numeric_limits<double>::max() as a special flag?
Let's look at your "baseline" code, that you say you want to do the "equivalent" of:
std::vector<double> a;
std::vector<int> ind;
for (auto it = ind.rbegin(); it != ind.rend(); it++)
a.erase(a.begin() + *it);
What we gather from this is that ind
is a vector of indexes in a
which should be removed, and that they are sorted ascending. Those indexes must be removed from a
. I assume your goal is to do this efficiently in terms of space and time.
If you think about it in terms of the minimum number of operations required, you have to shift many/most/all of the elements in a
in order to erase the ones indicated by ind
. You don't want to erase()
several times because this means shifting some elements more than once. One optimal solution (in the general case, not imposing special requirements on the values in a
) looks like this:
size_t slow = 0; // where we are currently copying "to"
std::vector<int> inditer = ind.begin();
for (size_t fast = 0; fast != a.size(); ++fast) {
if (inditer != ind.end() && *inditer == fast) {
// "remove" this element by ignoring it
++inditer;
} else {
a[slow] = a[fast];
++slow;
}
}
a.resize(slow);
Now, you could probably reformulate this using STL algorithms and a custom predicate (functor) which remembers its "current" position in ind
, but it will not be much less code and it might be harder to understand.
Value of numeric_limits<streamsize>::max() in c++
isn't this a very large value exceeding my HDD space.
That's exactly the purpose of this value. You want to skip as many char as possible. In fact, this value does indicate infinite, since the count test is disabled for this value:
count characters were extracted. This test is disabled in the special
case when count equals std::numeric_limits< std::streamsize >::max()
Can C++ std::numeric_limits<float>::max() be accurately stored in a float and later compared?
For a given (non-NaN) float
variable, f
, it is guaranteed that f == f
is always true. Since myFloat
gets set to some float
value, of course it will compare equal to that same value.
You are apparently thinking of cases such as:
float f1 = 0.1;
float f2 = 1.0/10;
assert( f1 == f2 );
which might fail, but this will not fail:
float f1 = 0.1;
float f2 = 0.1;
assert( f1 == f2 );
Although the value stored in the variables may not be exactly equal to 0.1
but may have a different value instead, you will get the same value for both variables, and so they will compare equal.
Whatever value numeric_limits<float>::max()
happens to return, it is a fixed value that will compare equal to itself.
Related Topics
Get Current Working Directory in a Qt Application
There Are No Arguments That Depend on a Template Parameter
How to Use Makefiles in Visual Studio
Aliasing Struct and Array the C++ Way
Is Std::String Thead-Safe with Gcc 4.3
Can Templates Be Used to Access Struct Variables by Name
Automatic Copy Files to Output During Application Building
Why Does Initializing an Extern Variable Inside a Function Give an Error
C++ Remove_If on a Vector of Objects
How to Define a Move Constructor
Best Way to Do Variant Visitation with Lambdas
Llvm Get Constant Integer Back from Value*
Implementing Component System from Unity in C++
Cannot Use .Begin() or .End() on an Array
How to Create a Thread-Safe Singleton Pattern in Windows