错误:在此范围内未声明“ numeric_limits”

Error: ‘numeric_limits’ was not declared in this scope

本文关键字:numeric limits 未声明 范围内 错误      更新时间:2023-10-16

我正在编译下载的代码。在使用cmakelist制作文件时,我会在这一行中遇到以下错误:

VocTree::findPath(Mat &descriptor) {
    list<int> path;
    int idNode = 0;
    unsigned int numCh = _k;
    path.push_back(idNode);
    while (!isLeaf(idNode)) {
        //Search the closest sub-cluster
        int idClosest = 0;
        double minDist = numeric_limits<int>::max();
        for (size_t i = 0; i < numCh; i++) {
            int childId = idChild(idNode, i);
            int idxChild = _index[childId];
            double d = norm(descriptor, _centers.row(idxChild), _useNorm);
            if (i == 0 || d < minDist) {
                minDist = d;
                idClosest = childId;
            }
        }
        idNode = idClosest;
        path.push_back(idNode);
    }
    return path;
}

这是错误:

src/VocTree.cpp:872:26: error: ‘numeric_limits’ was not declared in this scope
         double minDist = numeric_limits<int>::max();
                          ^
src/VocTree.cpp:872:41: error: expected primary-expression before ‘int’
         double minDist = numeric_limits<int>::max();

已经使用了以下名称空间:

using namespace cv;
using namespace std;

您需要包括

    #include <limits>