C++ how to pass vector of objects by reference into a function, then into next function? -
i'm hoping can provide assistance here. here relevant portion of code i'm stuck on currently:
/////////////////////////////////////////////////////////////////////////////////////////////////// void matchblobs(std::vector<blob> &existingblobs, std::vector<blob> ¤tframeblobs) { (auto &existingblob : existingblobs) { existingblob.blncurrentmatchfoundornewblob = false; } (auto ¤tframeblob : currentframeblobs) { int intindexofleastdistance = 0; double dblleastdistance = 1000000.0; (unsigned int = 0; < 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 2nd arg on line !!!!!!! } else { addnewblob(currentframeblob, existingblobs); } } (auto &existingblob : existingblobs) { if (existingblob.blncurrentmatchfoundornewblob == false) { existingblob.blnstillbeingtracked = false; } } } /////////////////////////////////////////////////////////////////////////////////////////////////// void addblobtoexistingblobs(blob ¤tframeblob, 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; }
as noted on comment in code, i'm getting compiler error on line:
addblobtoexistingblobs(currentframeblob, existingblobs, intindexofleastdistance); // !!!! compiler error 2nd arg on line !!!!!!!
the error is:
error c2664 'void addblobtoexistingblobs(blob &,blob &,int &)': cannot convert argument 2 'std::vector<blob,std::allocator<_ty>>' 'blob &' objecttrackingcpp c:\users\cdahms\documents\visual studio 2015\projects\objecttrackingcpp2\objecttrackingcpp.cpp 186
can shed light on i'm doing wrong here? can find plenty of c++ examples of passing 1 basic data type variable (int, double, etc.) reference unable find examples involving passing vector of objects 1 function, function.
i'm using compiler ships visual studio 2015 community, default options chosen if makes difference.
i'm not sure direction go here, assistance appreciated.
it appears - error message - compiler knows function
void addblobtoexistingblobs(blob&, blob&, int&);
whereas, in implementation of
void matchblobs(std::vector<blob>&, std::vector<blob>&);
a function name of addblobtoexistingblobs
used, different prototype, namely
void addblobtoexistingblobs(blob& ,std::vector<blob>&, int&);
have checked that, somewhere in code, haven't prototype addblobtoexistingblobs
function gets compiler confused ?
Comments
Post a Comment