柊四千
1 weeks ago @Edit 1 weeks ago
[閒聊] 剛剛才驚覺
try{
int *a = new int[n];
for(int i=0; i<=n-1; ++i) {a[i] = new int[n];}
// TODO: deal with the nxn matrix |a|
for(int i=n-1; i>=0; --i) {delete[] a[i];}
delete[] a;
}catch(...) {std::cerr << "OOM\n";}
這樣寫可能會引發memory leak
柊四千
1 weeks ago
考慮那個for迴圈在i=k時丟了一個std::bad_alloc
即使有被catch-block接住 a以及a[0..k-1]都掰了
柊四千
1 weeks ago
對了被render出斜體的部分(aka 第2行的"a = new int")本來是前後各有一個*的
我不知道要怎麼讓plurk顯示原始內容
立即下載