【发布时间】:2013-08-30 06:53:08
【问题描述】:
我有一个向量QVector<float> dist;,我在其中保持所有维度的欧几里得距离。我保持尺寸如下:
QHash<int, QVector<float> > hash;
其中int 是键,值再次保存在QVector<float> 中。
当我尝试填写dist 时的代码如下:
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];
}
}
循环按预期计算所有内容,但在之后崩溃并出现内存错误:
QVector::at "index out of range" 中的 ASSERT 失败...
当我删除while 循环(计算将是错误的)时,应用程序不再崩溃。
【问题讨论】:
-
while 循环后 j 将等于 t。我怀疑 t 是哈希中的有效索引
-
什么是
a?point是什么?
标签: c++ qt loops while-loop