Tuesday, 27 August 2013

An issue when looping with while

An issue when looping with while

I have a vector QVector<float> dist; where I am keeping Euclidean
distances for all dimension that I have. I keep the dimensions as follows:
QHash<int, QVector<float> > hash;
Where int is for keys, and the values are kept again in QVector<float>.
The code when I try to fill the dist is following:
for(int i = 0; i < t; i++)
{
for(int j = 1; j < t; j++)
{
while( j <= i)
j++;
dist.push_back(qPow((a[i] - hash[i].at(point)), 2) +
qPow((a[j] - hash[j].at(point)), 2));
qDebug() << "Euclidean distance for Dim" << i << "and Dim" <<
j << " = " << dist[i];
}
}
The loop calculates everything as supposed, but crashes with a memory
error after :
ASSERT failure in QVector::at "index out of range"...
When I remove while loop (the calculations will be WRONG) the application
is not crashing any more.

No comments:

Post a Comment