Is it possible to prevent new from being used at certain points in the code?
The legacy code that I am developing with has a requirement that there is no dynamic memory allocation after the bootstrap has completed. We now want to test this.
If I was starting the development from scratch then I could write my own wrapper and use that, or overload operator new in a common base class.
Is there a way of overloading global new and then calling it?
No, you can’t “overload” global
new– only replace it. However in your replacement you can check for a global flag meaning “new allowed” (and throw an exception if that flag is not set) and change that flag from inside calling code. This won’t help against overloadedoperator newin classes unless you change each overload to also respect that flag.