操作数类型的问题

时间:2013-08-27 17:09:46

标签: c++ qt hash vector operand

我收到以下错误:

  

错误:'operator-'不匹配(操作数类型为'QVector'和'const float')

尝试时:

dist.push_back(qPow((clusterMeanCoordinate[t].at(i) - hash_notClustered[t].at(point)), 2) + qPow((clusterMeanCoordinate[w] - hash_notClustered[w].at(point)), 2));

请注意:

QHash<int, QVector<float> > clusterMeanCoordinate;
QHash<int, QVector<float> > hash_notClustered;
QVector<float> dist;

2 个答案:

答案 0 :(得分:1)

您的错误在这里:

dist.push_back(
    qPow( (clusterMeanCoordinate[t].at(i) - hash_notClustered[t].at(point) ), 2) + 
    qPow( (clusterMeanCoordinate[w] - hash_notClustered[w].at(point)), 2));
//         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

您要在QVectorconst float之间进行减法:

   clusterMeanCoordinate[w] - hash_notClustered[w].at(point)
// QVector                  - const float

您可以通过以下方式解决问题:

clusterMeanCoordinate[w].at(i) - hash_notClustered[w].at(point)
//                      ^^^^^^

答案 1 :(得分:0)

在表达式

clusterMeanCoordinate[w] - hash_notClustered[w].at(point)

您尝试从float中减去QVector