我想定义将从 QVector 中删除自定义类型对象和索引的函数。最初的来源如下:
Point PointCollection::RemovePoint(int index)
{
Point removedPoint = new Point(this[index].Id, this[index].X, this[index].Y);
this->remove(index);
updateCentroid();
return (removedPoint);
}
Point PointCollection::RemovePoint(Point p)
{
Point removedPoint = new Point(p.GetId(), p.GetX(), p.GetY());
this.remove(p);
updateCentroid();
return (removedPoint);
}
这不像我想的那样工作,因为new
. 然后我将源代码修改为以下内容:
Point PointCollection::deletePoint(int Index)
{
Point deleted = Point(this[Index].Id, this[Index].X, this[Index].Y);
this->remove(Index);
updateCentroid();
return(deleted);
}
Point PointCollection::deletePoint(Point point)
{
Point deleted = Point(point.GetId(), point.GetX(), point.GetY());
this->remove(point);
updateCentroid();
return(deleted);
}
现在Point PointCollection::deletePoint(int Index)
编译没有任何错误,但this->remove(point);
在Point PointCollection::deletePoint(Point point)
运行时编译时出现以下错误:
错误:没有用于调用“PointCollection::remove(Point&)”的匹配函数
Q1:我是否纠正了已删除new?
的问题 Q2:如何解决我遇到的错误。