What is the array form of 'delete'?

后端 未结 5 2083
时光取名叫无心
时光取名叫无心 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:51

    Just as RichieHindle stated above when you want to free the space dynamically allocated for an array pointed by data you have to put two brackets [] between the reserved word delete and the pointer to the beginning of the allocated space. Since data can point to a single int in memory as well as to the first element in the array this is the only way you let the compiler know that you want to delete the whole chunk of memory. If you don't do it the proper way the behaviour is "undetermined" (Stroustrup, The C++ Programming Language).

提交回复
热议问题