Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;如何通过引用将对象的向量传递到函数中,然后传递到下一个函数中?_C++ - Fatal编程技术网

C++ C++;如何通过引用将对象的向量传递到函数中,然后传递到下一个函数中?

C++ C++;如何通过引用将对象的向量传递到函数中,然后传递到下一个函数中?,c++,C++,我希望有人能在这里提供一些帮助。下面是我目前一直坚持的代码的相关部分: /////////////////////////////////////////////////////////////////////////////////////////////////// void matchBlobs(std::vector<Blob> &existingBlobs, std::vector<Blob> &currentFrameBlobs) {

我希望有人能在这里提供一些帮助。下面是我目前一直坚持的代码的相关部分:

///////////////////////////////////////////////////////////////////////////////////////////////////
void matchBlobs(std::vector<Blob> &existingBlobs, std::vector<Blob> &currentFrameBlobs) {

    for (auto &existingBlob : existingBlobs) {
        existingBlob.blnCurrentMatchFoundOrNewBlob = false;
    }

    for (auto &currentFrameBlob : currentFrameBlobs) {

        int intIndexOfLeastDistance = 0;
        double dblLeastDistance = 1000000.0;

        for (unsigned int i = 0; i < existingBlobs.size() - 1; i++) {
            if (existingBlobs[i].blnStillBeingTracked == true) {
                double dblDistance = distanceBetweenBlobs(currentFrameBlob, existingBlobs[i]);

                if (dblDistance < dblLeastDistance) {
                    dblLeastDistance = dblDistance;
                    intIndexOfLeastDistance = i;
                }
            }
        }

        if (dblLeastDistance < currentFrameBlob.dblDiagonalSize * 1.5) {
            addBlobToExistingBlobs(currentFrameBlob, existingBlobs, intIndexOfLeastDistance); // !!!! compiler error for 2nd arg on this line !!!!!!!
        } else {
            addNewBlob(currentFrameBlob, existingBlobs);
        }

    }

    for (auto &existingBlob : existingBlobs) {
        if (existingBlob.blnCurrentMatchFoundOrNewBlob == false) {
            existingBlob.blnStillBeingTracked = false;
        }

    }

}

///////////////////////////////////////////////////////////////////////////////////////////////////
void addBlobToExistingBlobs(Blob &currentFrameBlob, std::vector<Blob> &existingBlobs, int &intIndex) {

    existingBlobs[intIndex].contour = currentFrameBlob.contour;
    existingBlobs[intIndex].boundingRect = currentFrameBlob.boundingRect;
    existingBlobs[intIndex].ptCurrentCenter = currentFrameBlob.ptCurrentCenter;
    existingBlobs[intIndex].dblDiagonalSize = currentFrameBlob.dblDiagonalSize;
    existingBlobs[intIndex].dblAspectRatio = currentFrameBlob.dblAspectRatio;

    existingBlobs[intIndex].vectorOfAllActualPoints.push_back(currentFrameBlob.ptCurrentCenter);

    existingBlobs[intIndex].blnStillBeingTracked = true;
    existingBlobs[intIndex].blnCurrentMatchFoundOrNewBlob = true;
}
错误是:

Error C2664 'void addBlobToExistingBlobs(Blob &,Blob &,int &)': cannot convert argument 2 from 'std::vector<Blob,std::allocator<_Ty>>' to 'Blob &'  ObjectTrackingCPP   c:\users\cdahms\documents\visual studio 2015\projects\objecttrackingcpp2\objecttrackingcpp.cpp  186
错误C2664“void addBlobToExistingBlobs(Blob&,Blob&,int&”):无法将参数2从“std::vector”转换为“Blob&”ObjectTrackingCPP c:\users\cdahms\documents\visual studio 2015\Project\objecttrackingcpp2\ObjectTrackingCPP.cpp 186
有人能解释一下我做错了什么吗?我可以通过引用引用大量的C++实例来传递一个基本的数据类型变量(int,双,等等),但是我找不到任何例子,包括将一个向量的向量传递到一个函数,然后再进入另一个函数。 我使用的是VisualStudio2015社区附带的编译器,如果有区别,则选择默认选项


我不知道该往哪个方向走,如果您能提供任何帮助,我将不胜感激。

从错误消息中可以看出,编译器知道您的函数是

void addBlobToExistingBlobs(Blob&, Blob&, int&);
鉴于,在您实施

void matchBlobs(std::vector<Blob>&, std::vector<Blob>&);

您是否检查过,在您的代码中的某个地方,您没有另一个
addBlobToExistingBlobs
函数的原型使编译器感到困惑?

检查
addBlobToExistingBlobs
的声明。编译器认为它将单个
Blob
作为其第二个参数,而不是试图传递的
Blob
的向量。我的猜测是,你在标题中声明的内容与你在代码中声明的内容不同。这是一个很好的决定,你死定了,我犯了一个愚蠢的错误。我更改了函数原型以匹配上面的代码,它编译起来没有问题。再次感谢。在这里和那里进行一点
const
会有所帮助。对不起,我只是想你在前面的评论中找到了解决方案。。。我错了!无论如何,谢谢你,正如你所说,我更新了函数原型,代码运行得很好,再次感谢。
void matchBlobs(std::vector<Blob>&, std::vector<Blob>&);
void addBlobToExistingBlobs(Blob& ,std::vector<Blob>&, int&);