You can write
new(foo, bar) MyClass;
In this case the following function is called
void*operator new(std::size_t, Foo, Bar){
...
}
You can now call
new(__LINE__, __FILE__) MyClass;
and use the data with
void*operator new(std::size_t, unsigned line, const char*file){
...
}
Adding a macro
#define new new(__LINE__, __FILE__)
to the code being monitored will catch most invocations without needing source code changes.
It's not perfect as you could call the operator new directly for example. In that case the preprocessor will turn your code into garbage. I know of no better way though.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…