0
我在test.h文件: double *condmatrix
- 全局變量 然後在主程序中我做的:刪除和重新分配全局指針 - 段錯誤
cycle_start {
proc1() {
condmatrix = new double[maxdim];
....simple work with the array itself
}
proc2() {
delete [] condmatrix;
}
}//cycle finish
這給了我一個段錯誤。我嘗試用[]語法刪除,沒有和其他方式,它仍然給出了段錯誤。 Maxdim因週期而異。
看起來沒問題。你能給我們一個最小的完整例子嗎? – Beta 2013-04-11 13:56:08
也許你試圖刪除它兩次 – Alon 2013-04-11 13:56:27
maxdim的值是什麼?參見[link](http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory) – 2013-04-11 14:07:45