我有一个程序包含许多cpp文件,我尝试创建一个makefile,但是当我运行它时,我得到了一些与此函数相关的错误:
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;
}
}
}
我尝试包含:
:
#include <limits>
using namespace std;
但是当我编译我的程序时,出现了以下错误:
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
我在网上进行了很多研究,但没有找到解决我的问题的方法。
std::numeric_limits<int>::infinity
没有用,因为整数没有无穷大的概念。建议使用max代替。 - Baum mit Augenusing namespace std;
相关的无聊问题,例如编译器在您尝试使用变量max
时捕捉到std::max
,或者其他类似的情况。专业提示:忘掉using namespace std;
,它带来的危害大于好处。 - Baum mit Augen#include <limits>
出现在同一源文件中,并且在你的有问题的代码之前,我使用gcc没有遇到任何问题。简而言之:无法重现错误。 - Peter