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と (計算が正しくなくなります)、アプリケーションはクラッシュしなくなりました。