[問題] 塞ADDR進VECTOR為何會CRASH
看板C_and_CPP (C/C++)作者ot32em (reverse(wasefo);)時間16年前 (2010/01/17 23:16)推噓0(0推 0噓 7→)留言7則, 2人參與討論串1/1
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
我有個class mat大小280
想要塞入 vector<mat*> heap
可是我在塞第三個addr of object時
就CRASH了 而且每次都是第三個就GG 是用固定SAMPLE
vector有限大小嗎!@?!?!
mat* child=0;
...
child = new mat(selected->childrenInstance[drt], mat::id_counter++,
mat::reverse_direction(drt), selected);
希望得到的正確結果:
可以塞得進去
程式跑出來的錯誤結果:
CRASH
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
dev-c++ on win7
有問題的code: (請善用置底文標色功能)
vector<mat*> heap;
heap.push_back(input); heap_push(heap.begin(),heap.end(),mat::compare);
...
mat* child=0;
mat* selected=heap[0];
...
...
child = new mat(selected->childrenInstance[drt], mat::id_counter++,
mat::reverse_direction(drt), selected);
cout << " new ok " << endl; // 這行OK
heap.push_back(child);
cout << " push ok " << endl; // 這行沒跑出來就CRASH了
所以我想應該是在PUSH時GG
補充說明:
是因為我沒 delete 嗎!?!?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.13.191
→
01/18 02:10, , 1F
01/18 02:10, 1F
→
01/18 02:15, , 2F
01/18 02:15, 2F
→
01/18 14:38, , 3F
01/18 14:38, 3F
→
01/18 14:39, , 4F
01/18 14:39, 4F
→
01/18 14:40, , 5F
01/18 14:40, 5F
→
01/18 14:41, , 6F
01/18 14:41, 6F
→
01/18 14:41, , 7F
01/18 14:41, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章