gpt4 book ai didi

c++ - 运算符 == 错误

转载 作者:行者123 更新时间:2023-11-30 04:15:22 27 4
gpt4 key购买 nike

<分区>

我已经定义了一个类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 类的私有(private)变量。在我定义的构造函数中:

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);
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com