我已经定义了一个类点。我还有一个类 PointCollection :class PointCollection: public QVector<Point>
在实现某些方法时,我收到以下错误:
错误:'operator==' 不匹配(操作数类型为 'Point' 和 '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);
}