pointers - C++ Deallocating memory giving me aborted dump? -


i have deconstructor suppose deallocate pointers made it's not working should. heres part of class declares pointers

private:     struct edge {         vertex* node;     };      struct vertex {         vector< edge > adjlist;         vertex *path;      };      vector<vertex*> vertices;     priority_queue< vertex* > pq; 

and declare new vertexs in functions vertex* v = new vertex. i've been told not have worry deleting these pointers. heres function deallocates memory called deconstructor

void makeempty( ) {     for(int = 0; < total; ++i)         makeempty( vertices[ ] );     total = 0; }  void makeempty( vertex * & v ) {     for( int = 0; < v->adjlist.size(); ++i ){         //delete v->adjlist[ ].node;         //v->adjlist[ ].node = nullptr;     }     if ( v->path != nullptr ) {         makeempty( v->path);         delete v;         v = nullptr;     } } 

i commented out adjlist because experimenting different ways on how make worked nothing is. can me?

forgot mention of these pointers related same vertex/node. of vertex/nodes used inside vertices

edit: got worked, turns out overcomplicating things , needed this

void makeempty( vertex * & v ) {         delete v;         v = nullptr; } 

"vertex* v = new vertex i've been told not have worry deleting these pointers."

well, they're raw pointers. have worry deleting them. easiest solution put vertices in graph class, let own everything, , don't worry ownership @ node level.

things bit hairy if cutting graphs in two, or doing operations might cut graph in two. then, it's not hard have operation extracts new graph old graph, , transfer affected nodes new graph.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -