Why do we even need the “delete[]” operator?

前端 未结 7 883
粉色の甜心
粉色の甜心 2020-12-03 10:02

This is a question that\'s been nagging me for some time. I always thought that C++ should have been designed so that the delete operator (without brackets) wor

7条回答
  •  情话喂你
    2020-12-03 10:14

    Since everyone else seems to have missed the point of your question, I'll just add that I had the same thought some year ago, and have never been able to get an answer.

    The only thing I can think of is that there's a very tiny bit of extra overhead to treat a single object as an array (an unnecessary "for(int i=0; i<1; ++i)" )

提交回复
热议问题