Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To erase specifice element in the Vector

Status
Not open for further replies.

amanyasin

Technical User
Feb 7, 2003
28
Hi,
Dear all,

On each iteration in Vector , i want to deduce one element and delete it. then pass remaining vector to my function.

so, problem is this. it is not erasing the specific vector
Code:
typedef std::vector < int > nodeList;
nodeList temp;
nodeList neighborX = this->computeNeighbors(x);

for (nodeList::iterator iter = neighborX.begin(); iter != neighborX.end(); ++iter)
{
int y = *iter;
temp = neighborX;

neighborX.erase(iter); // deduce first variable as y and delete it from the list.

graph = this->computeIndependence(ds, graph, x, y, neighborX, condVariables, sep);

neighborX = temp;

}


But it is giving an error.
Code:
error: program: c:\.....\....\.....\vector line 117

Expression : ("this->_Mycont != NULL",0)


i tried to find an error but i am fail,

if i remove this line then no problem

Code:
neighborX.erase(iter);

so please suggest me an other way to remove an element. thanks in advance.
 
You invalidate iter iterator by the last assignment in the loop body.
 
Have you ever wondered why the vector::erase() function returns an iterator? This is why.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top