| Phiru (105) | |
|
I am adding int type into vector called "vi" several times like this. std::vector<int> vi; void addFunc(int *a, int cnt) { vi.erase(vi.begin(), vi.end()); vi.clear(); for(int i=0; i<cnt; i++) vi.push_back(a[i]); } and I call the addfunc N times every sec. And sometimes it has runtime error on vi.push_back line. (called stack says "_CrtIsValidHeapPointer") i don't know how come it has that problem. any idea? | |
|
|
|
| cire (2347) | |
|
I think it is more likely to be a problem with either a or cnt being inaccurate or invalid than a problem with the vector. You can get rid of the erase call, by the way. clear is sufficient. | |
|
|
|
| Phiru (105) | |
|
The first time, I did just call clear func. As someone said, just using clear to clear every elements in Vector is not sufficient. should call erase before clear. So i coded like that. And I am looking it out to find error. Thanks anyways. | |
|
|
|
| cire (2347) | ||
Someone was wrong. | ||
|
|
||
| vlad from moscow (3662) | |
| Function clear is equivalent to erase(vi.begin(), vi.end()). So there is no need to call in fact the same function two times. | |
|
|
|
| Phiru (105) | |
|
I got wrong information. Thanks to correct my wrong data in my head. | |
|
|
|