Delete pointer to multidimensional array in class through another pointer - how?

前端 未结 4 2096
眼角桃花
眼角桃花 2020-12-04 03:18

I have a pointer to a class, that have a pointer to a multidimensional array but I can\'t seem to delete it from memory when I need to or set it to NULL.

#de         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-04 04:16

    If you've dynamically created an array, then delete it with delete[]. You have to give delete[] a pointer to the start of the array, however, not an element of the array!

    If you want the elements to be deletable, then they have to be dynamically allocated separately.

    So you have to have a multi-dimensional array of pointers;

    int *(*pArray)[X][Y];
    

    Then dynamically assign each one, which yes is a pain.

    It is interesting, however, that you are even attempting to do this, why do you want to delete single elements?

提交回复
热议问题