I am trying to get the result of this function:
C++:
void EM::getCovs(std::vector<Mat>& covs) const
My question is how to get the covs
? I kept getting compiling error. Here is my code.
const vector<Mat> &covs;
model->getCovs(covs);
I get error said
Declaration of reference variable 'covs' requires an initializer.
(1) This is the correct way to get data from getCovs, or
(2) I need to initialize 'covs' like the error showed.
The &
in the parameter list void getCovs(std::vector& covs)
means that you pass a reference to an existing vector.
You should declare local storage for a vector:
vector<Mat> covs;
then you can pass a reference to it into getCovs
:
model->getCovs(covs);
What you wrote (vector<Mat>& covs;
) is a local variable that references another vector; however you haven't provided another vector for it to reference. The const
also prevents it from being modified, but you want it to be modified by the getCovs function.