Reputation: 1
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.
Upvotes: -1
Views: 133
Reputation: 118761
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.
Upvotes: 1
Reputation: 18972
Just declare it as vector<Mat> covs;
. You want a real vector, not a reference, to pass to the function. And you don't want it to be const because you want the function to write into it.
Upvotes: 0