的__點點滴滴

來源:互聯網
上載者:User

問題:編譯,連結都沒問題,運行結束時出現Debug error錯誤,DAMAGE:After Normal block (#187) at 0x00033160

源碼:

//子函數問題,與主函數無關, 主函數的have[pn][rn],need[i][j],offer[rn]被傳遞,返回一整數值

int issafe(vector < vector<int> >& have, vector < vector<int> >& need, vector <int>& offer)

{
int safe=0;

vector < vector<int> >have1(pn);//全域變數:pn,rn
vector < vector<int> >need1(pn);
vector <int> offer1(rn);

for(int i=0; i<pn; i++)
{
   for(int j=0; j<rn; j++)
   {
   have1[i][j]=have[i][j]; //have1[i].push_back(have[i][j]);
    need1[i][j]=need[i][j];//need1[i].push_back(need[i][j]);
   }
}

return safe;

}

原因:主要是對於動態分配的記憶體的錯誤使用。have1向量只知道包含pn個一維向量,而卻不知道每個一維向量有多少個元素,因此have1[i][j]=have[i][j]; 是錯誤的;這樣訪問到錯誤的記憶體---那個地址的內容未知。
出現 debug error ,在於VC檢測到了這個錯誤資訊。--

解決:綠色部分改成紅色部分

參考http://www.programfan.com/club/showpost.asp?id=146259&t=o:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.