Jump to content
  • Advertisement
Sign in to follow this  
Jedite

Access Violation when pushing to a list

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

list <WorkStation*> pStations;
WorkStation *temp = new WorkStation;
temp->SetStation(StationData);
pStations.push_back(temp);

Setstation is a function to fill up all the values in station.. Stationdata is just a char* with the data. For some reason im getting an access violation when trying to push temp into the list. I dont understand why.. any help is welcomed

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Why are you using pointers? Why not just use list instead? The list automatically stores a copy of the data that is separate from the one that is passed in.

For example:
list intVec;
intVec.push_back(1);
intVec.push_back(2);
intVec.push_back(3);
intVec.push_back(4);
intVec.push_back(5);

When the elements were pushed on the back of the list, no pointers at all were used, and this list will have values 1, 2, 3, 4, 5 after all of the push_backs are finished.

Is the crash happening specifically at the push_back call? What happens if you add another simple, non-intrusive line after it? Also, does it happen if you switch to a different STL container, say vector?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Why not just use list instead? The list automatically stores a copy of the data that is separate from the one that is passed in.


One reason NOT to do this is that enforcing a copy on a user defined type can be VERY costly.

I vaguely recall reading something that suggested using push_back on an empty list since was bad since the list doesn't have an end (not every implementation of the STL is 'standard')... but I am probably wrong. Can you push the first item to the front of the list? If this works, can you then push something onto the back of the list?

Cheers,

Timkin

Share this post


Link to post
Share on other sites
I see nothing wrong with the code you posted. The problem is probably somewhere else. Perhaps SetStation or the constructor is overflowing an array or something

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!