I have a program which contain many cpp files,I try to create a makefile but when I run it I got some errors related to this function:
void replace_infinites(cv::Mat_<int>& matrix) {
const unsigned int rows = matrix.rows,columns = matrix.cols;
// assert( rows > 0 && columns > 0 );
if(rows==0 || columns==0)
return;
double max = matrix(0, 0);
const auto infinity = std::numeric_limits<int>::infinity();
// Find the greatest value in the matrix that isn't infinity.
for ( unsigned int row = 0 ; row < rows ; row++ ) {
for ( unsigned int col = 0 ; col < columns ; col++ ) {
if ( matrix(row, col) != infinity ) {
if ( max == infinity ) {
max = matrix(row, col);
} else {
max = std::max<int>(max, matrix(row, col));
}
}
}
}
// a value higher than the maximum value present in the matrix.
if ( max == infinity ) {
// This case only occurs when all values are infinite.
max = 0;
} else {
max++;
}
for ( unsigned int row = 0 ; row < rows ; row++ ) {
for ( unsigned int col = 0 ; col < columns ; col++ ) {
if ( matrix(row, col) == infinity ) {
matrix(row, col) = max;
}
}
}
} I tried to include :
#include <limits>
using namespace std;
But when I compile my program I get these errors:
munkres.cpp: In function ‘void replace_infinites(cv::Mat_<int>&)’:
munkres.cpp:44:16: error: ‘infinity’ does not name a type
munkres.cpp:49:38: error: ‘infinity’ was not declared in this scope
munkres.cpp:60:17: error: ‘infinity’ was not declared in this scope
munkres.cpp:69:38: error: ‘infinity’ was not declared in this scope
I make a lot of research on the net but I didn't get any solution to fix my problem.
It seems likely that you are not compiling with C++11 or higher, since your compiler is complaining about the following line:
const auto infinity = std::numeric_limits<int>::infinity();
Assuming you have indeed included #include <limits>
, there is nothing wrong with that line except the use of auto
. Without C++11, the compiler doesn't know what auto
is. Compile with C++11 or higher, or change auto
to int
.
Unrelated, and this was pointed out in the comments, but using numeric_limits<int>::infinity
is an awful, awful way of checking things. It doesn't make any sense to make an int
comparison in regards to infinity. Prefer to usenumeric_limits<int>::max
instead (or whatever else suits your purposes).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.