📜  双数组大小 c++ 代码示例

📅  最后修改于: 2022-03-11 14:44:46.445000             🧑  作者: Mango

代码示例1
void enlarge(int *& array, int size) {
//                ^
// Use a reference to a pointer.

    int *dbl = new int[size*2];
    for (int i = 0; i < size; i++) {
    //                  ^
    // Iterate up to size, not size*2.
        dbl[i] = array[i];
    }
    delete[] array;
    //    ^
    // Use delete[], not delete.
    array = dbl;
}