Overloading operator delete[], iostream already does?

I've been playing around with overloading operator new and operator delete, and I am encountering a result that surprises me:

Suppose I overloaded operator delete but not operator delete[]. Then, I allocate a heap array, like int* p = new int[40];, and then delete []p;.

The result is:

* If I have not #included <iostream>, my operator delete IS called when delete []p is invoked.

* If I have #included <iostream>, my operator delete is NOT called when delete []p is invoked. (I can correct this by writing an overload for delete[] as well.)

I'm trying to figure out why this is. Why does it default to invoking my operator delete in response to a delete []p, but change this behavior when iostream is included?

My best guess is this: Maybe the compiler's default operator delete[] defaults to invoking operator delete, which I have then overridden, but iostream has its own overload for operator delete[] which does something else, and that's why I would need to personally overwrite both delete and delete [] when iostream is present.

But that's just a guess. And it would still seem weird to me that iostream would overload delete[] at all, particularly in such a way that doesn't cascade down to my delete.

Any insights? (I'm using Visual Studio Express 2012.)
Topic archived. No new replies allowed.