I am building a QList<QList<double>> * the following way, to be returned in function randomPoint():
QList<QList<double>> *solverMethod::randomPoint(double* bottom_, double* top_, int items_)
{
QList<QList<double>> *lstPt_ = new QList<QList<double>>;
for(int i=0;i<items_;i++)
{
QList<double> pt_;
lstPt_->append(pt_);
for(int j=0;j<m_ndim;j++)
{
pt_.append(TRandom::rand(bottom_[j],top_[j]));
}
}
return lstPt_;
}
But with a stopping point after for loop, I notice that pt_ is filled in properly (m_ndim elements), whereas lstPt is made of item_ empty QList<double>. What is happening?
This puts a copy of
pt_in the outer list. You then populate the localpt_, leaving the copy empty. You should move this line after the loop that fillspt_. Specifically: