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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list.erase(it) problem

Status
Not open for further replies.

pegazaus

Instructor
Aug 16, 2005
22
SE
Hello , First I wanna thank all the people that hade helpt with "string to int" problem.
I'm using Visual studio 6.0 and I 'm woking on the following code:
Code:
list<Figure *>HildingsKakor;
.....
Figure* p = new Figure("somebitmp.bmp, 100, 100");
HildingsKakor.push_back(p);
Figure* p = new Figure("somebitmp.bmp, 100, 200");
HildingsKakor.push_back(p);
...
for(list<Figure *>::iterator it=HildingsKakor.begin(); it!=HildingsKakor.end();it++){
krockar = pJanos->operlapsWith(**it);
  if(krockar){
	[b]HildingsKakor.erase(it);[/b][COLOR=red]this line is generating error [/color]
	}
   }
It seem that an error is generated when I try to erase an object from the list.
I appriciate all help.
 
What does the error say?


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
It says nothing, The compilation goes fin , but when executing the program I get like error and the program crashes. You no like error has occured and send report and so on.
 
Try this instead:

for(list<Figure *>::iterator it=HildingsKakor.begin(); it!=HildingsKakor.end();/*NOTHING HERE*/){
krockar = pJanos->operlapsWith(**it);
if(krockar){
it = HildingsKakor.erase(it);
} else {
it++;
}
}

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top