我是C++新手,目前正在使用STL容器。 我執行一個嚴重的問題nodeStack.push(startnode)
- 編譯器顯示了堆棧推送導致嚴重錯誤
嚴重錯誤檢測c0000374
Followign代碼顯示功能,其中發生提到的錯誤:
vector<int> Graph::iterativeDepthSearch(map<int, vector<int>> adjlist, int startnode) {
stack<int> nodeStack;
vector<int> visitList;
// Knotenbesuchsliste initialisieren
int* val = new int(adjlist.size());
for (int i = 0; i < (int) adjlist.size(); i++) {
val[i] = 0;
}
int cnt = 1;
nodeStack.push(startnode);
....
}
的錯誤發生在行nodeStack.push(startnode);
中,startnode用0初始化。
totowtwo答案將幫助你。我只想補充說,初始化你的數組時,調用ZeroMemory(如果可用)或memset就足夠了。 – Hyperboreus 2011-06-16 19:44:17
在一個不相關的說明中,你的意思是把你的地圖複製到函數中,而不是使用const const map
Troubadour
2011-06-16 19:48:39
@hyperboreus甚至更好,std :: fill! – totowtwo 2011-06-16 20:15:26