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

It’s so that the destructors of the individual elements will be called. Yes, for arrays of PODs, there isn’t much of a difference, but in C++, you can have arrays of objects with non-trivial destructors.

Now, your question is, why not make new and delete behave like new[] and delete[] and get rid of new[] and delete[]? I would go back Stroustrup’s “Design and Evolution” book where he said that if you don’t use C++ features, you shouldn’t have to pay for them (at run time at least). The way it stands now, a new or delete will behave as efficiently as malloc and free. If delete had the delete[] meaning, there would be some extra overhead at run time (as James Curran pointed out).

Leave a Comment