I've been asked to implement a design spec that has a curious proviso on it: an overload on operator new as a member in one of the classes. The spec requires that the overloaded new call the global new -- rather than just using malloc() -- and be easily able to have extra statements to work on the new object inserted before returning.

It seems to me that the design is aimed at producing objects in one class hierarchy (but not the others) that are aware of whether they're on the heap or the stack (since automatic local variables shouldn't initialise via new), while still allowing the regular operator delete to clean them up, without having to overload it.

The reason for the malloc()/free() aversion wasn't addressed when I asked about it. All the examples of overloading new I've been able to find use malloc(), with free() in an overloaded delete.

After reading through VC++'s documentation regarding overloading new, I can't quite see how to do this, since new/delete are overloads I've never had to write before. new returns void*, but casting it straight to the type the overload is a member of should be safe, yes? Global new should be reachable by ::new, but what parameters need to be passed, and what would the call look like?