list <WorkStation*> pStations;
WorkStation *temp = new WorkStation;
temp->SetStation(StationData);
pStations.push_back(temp);
Access Violation when pushing to a list
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?
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?
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement