我已經定義了一個類Point。我也有一類PointCollection:class PointCollection: public QVector<Point>
這裏實現一些方法我獲得以下錯誤時:運算符==錯誤
error: no match for 'operator==' (operand types are 'Point' and 'const Point')
這裏是我有這樣的錯誤代碼部分:
Point PointCollection::getNearestPointToCentroid()
{
float minDist = 0.0;
int NearestPointToCentroidIndex = -1;
while(!this->empty())
{
Point point;
Point centroid;
float dist = PointT.calculateEuclideanDist(point, centroid);
if(this->indexOf(point) == 0)
{
minDist = dist;
NearestPointToCentroidIndex = this->indexOf(point);
}
else
{
if(minDist > dist)
{
minDist = dist;
NearestPointToCentroidIndex = this->indexOf(point);
}
}
}
return(this[NearestPointToCentroidIndex]);
}
其中:Point centorid;float X;float Y;int Id;
是私有變量的PointCollection類。在構造函數中,我定義:
PointCollection::PointCollection()
{
//centorid = new Point;
Id = PointT.GetId();
X = PointT.GetX();
Y = PointT.GetY();
}
而且
float Point::calculateEuclideanDist(Point point_1, Point point_2)
{
float x1 = point_1.x, y1 = point_1.y;
float x2 = point_2.x, y2 = point_2.y;
float dist = qSqrt(qPow(x2 - x1, 2.0) + qPow(y2 - y1, 2.0));
return (dist);
}
你可以爲'Point'顯示'operator =='嗎? – juanchopanza
'return(this [NearestPointToCentroidIndex]);'你真的想寫什麼? –
@ juanchopanza:我很抱歉,但我沒有真正明白你的意思。 Point只是一個類,另一個類如下所示:class PointCollection:public QVector。如果我的理解是正確的,operator ==應該是QVector的。 –
Mike