Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) Can you help me solve this memory leak in my polygon class. I wrote a destructor for Polygon and I think I need a

(C++) Can you help me solve this memory leak in my polygon class. I wrote a destructor for Polygon and I think I need a for loop to delete the objects in the object array but I'm not sure how to delete them:

Error:

image text in transcribed

Where memory leaked happened:

TEST_CASE("Testing container (GIS) operations") { //Memory leak GIS taxMap; SECTION("Check file availability") { REQUIRE(!taxMap.readFile("zzzzz.zzzz")); REQUIRE(taxMap.readFile("simple-polygons.txt")); }

SECTION("Check point that isn't inside any of the polygons") { taxMap.readFile("simple-polygons.txt"); CHECK("Not Found" == taxMap.findParcelName(Point(-1, -1))); }

SECTION("Check for point inside polygon") { taxMap.readFile("simple-polygons.txt"); CHECK("squareParcel" == taxMap.findParcelName(Point(1, 1))); CHECK("wideRectangleParcel" == taxMap.findParcelName(Point(5, 4))); } }

Polygon Class:

class Polygon: public Point { public: Polygon();

Polygon(string n, Point points1[10], int vertexs);

Polygon(const Polygon &p1){ name = p1.name; vertexCount = p1.vertexCount; for(int i = 0; i

~Polygon(){ cout//DELETE POINTER OBJECTS FROM OBJECT ARRAY TO GET RID OF MEMORY LEAK

Polygon& operator=(const Polygon &other); friend istream& operator>>(istream& in, Polygon& p); string GetName(); int getVertexCount(); Point* getVertex(int vertex); bool contains(Point point); private: string name; int vertexCount; Point points[10]; };

Polygon::Polygon(){ name = ""; vertexCount = 0; points[10] = {}; }

Polygon::Polygon(string n, Point points1[], int vertexs){ name = n; vertexCount = vertexs; for(int i = 0; i

string Polygon::GetName(){ return name; }

Point* Polygon::getVertex(int vertex){ //return specific point from array using vertex as position return &points[vertex]; }

int Polygon::getVertexCount(){ return vertexCount; }

Polygon& Polygon::operator=(const Polygon &other){ name = other.name; vertexCount = other.vertexCount; for(int i = 0; i

istream& operator>>(istream& in, Polygon& p){ string name; int vertexCount; in >> name >> vertexCount; p.name = name; p.vertexCount = vertexCount; for(int i = 0; i > p.points[i]; } return in; }

bool Polygon::contains(Point point){ int i; int j; bool x = false; for (i = 0, j = vertexCount-1; i point.getY()) != (points[j].getY()>point.getY())) && (point.getX() R Run Container (GIS) tests make: *** No rule to make target 'gis.0', needed by 'test-4-gis'. Stop. X Run Container (GIS) tests : error:: Error: Exit with code: 2 and signal: null : Memory leak check polygon class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions