Search code examples
c++qthashvectoroperand

Issue with operand types


I get the following error:

error: no match for 'operator-' (operand types are 'QVector' and 'const float')

when trying to do:

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

Note that:

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

Solution

  • Your error is here :

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

    Here you are making a substraction between a QVector and a const float :

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

    You can solve it by doing :

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