vector - insert object to set c++ -
i have following fucntion handle points (among set of points) type start_vertex:
void handlestartvertex(vertex vi) { cout << "start vertex begins ######################################################################################" << endl; cout << "handling start " << vi << vertextype[vi.type] << endl; halfedge *ei = vi.incidentedge; std :: vector<halfedge > :: iterator it,itprev; cout << "origin of incident edge " << *(ei->origin) << endl; //insert ei in tow , set helper vi ei->sethelper(&vi); tow.push_back(*ei); cout << "content of tow in start_vertex" << endl; for(it = tow.begin();it != tow.end();it++) cout << "origin of edge " << *((*it).origin) << " helper " << *((*it).helper) << endl; cout << "start vertex stops ######################################################################################\n\n" << endl; }
where tow :
vector<halfedge > tow;
problem when setting helper of edge , pushing vector tow,for edges present in tow, helper changes of edge being presently pushed. not understanding why happening? work around appreciated. here results can make question more clear.
start vertex begins ########################################################################### handling start (2,9) start_vertex origin of incident edge (2,9)
content of tow in start_vertex
origin of edge (6,12) helper (2,9)
origin of edge (9,11) helper (2,9)
origin of edge (2,9) helper (2,9)
start vertex stops ############################################################################
correct result should getting is:
origin of edge (6,12) helper (6,12)
origin of edge (9,11) helper (9,11)
origin of edge (2,9) helper (2,9)
the vertex vi destroyed @ return of function. setting helper memory occupied vertex vi, , memory occupied vertex (2, 9) when last print. pass pointer vertex vi input function:
void handlestartvertex(vertex* vi) { ... }
Comments
Post a Comment