What if, memory allocated using malloc is deleted using delete rather than free

前端 未结 7 1694
渐次进展
渐次进展 2021-02-09 03:45

I came across an issue which I could not resolve.

My question is, if I used malloc to allocate memory and then memory block is delete using delete

相关标签:
7条回答
  • 2021-02-09 04:24

    Many good reasons have already been given. I'll add one more reason: the new operator can be overriden in c++. This allows the user to specify their own memory management model if they so desire. Although this is pretty uncommon, its existence is just one more reason why malloc and new, delete and free cannot be used interchangeably. This is for the reason described by @Patz.

    0 讨论(0)
提交回复
热议问题