QVector에서 자체 정의 유형의 객체와 색인을 삭제하는 함수를 정의하려고합니다. 은 원래 소스는 다음과 같이이었다 : 나는 때문에 new
생각으로 작동하지 않는포인터 및 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);
}
.
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)
가 오류없이 컴파일하지만 Point PointCollection::deletePoint(Point point)
에서 this->remove(point);
는 다음과 같은 오류 컴파일 작용 :
error: no matching function for call to 'PointCollection::remove(Point&)'
Q1 : 그럼 다음에 소스를 수정 내가 new?
을 제거하는 올바른 짓 질문 2 : 내가 겪고있는 오류를 해결하는 방법.
'Point removedPoint = new Point'? 그게 포인터가 아니어야합니까? 코드에 문제가 많습니다. "자체 정의 유형 객체"란 무엇입니까? – dtech
'this [someIndex]'라고 말할 수는 없습니다 (물론 가능하지만 재앙이 될 것입니다). – juanchopanza
혹시 이것을 시도해 보셨습니까 = 0 : – user2672165