What is the array form of 'delete'?

后端 未结 5 2089
时光取名叫无心
时光取名叫无心 2020-12-01 16:30

When I compiled a code using the array name as a pointer, and I deleted the array name using delete, I got a warning about deleting an array without using the a

5条回答
  •  我在风中等你
    2020-12-01 16:53

    The array form of delete is:

    delete [] data;
    

    Edit: But as others have pointed out, you shouldn't be calling delete for data defined like this:

    int data[5];
    

    You should only call it when you allocate the memory using new like this:

    int *data = new int[5];
    

提交回复
热议问题