I have overloaded new and delete operators. I want to save pointers to 'old' new
and delete
to call it into 'new' new
and delete
. For example:
#include "h.h"
void * operator new ( size_t size, /*args*/ ) throw (std::bad_alloc)
{
void * p = 0;
p = original_new(size); //calling for 'old' new
//some code
return p;
}
And the similar operator delete
.
So, I'm trying in my header file to type the following:
static void * (*original_new)(size_t) = ::operator new;
static void * (*original_new_arr)(size_t) = ::operator new[];
static void (*original_delete)(void *) = ::operator delete;
static void (*original_delete_arr)(void *) = ::operator delete[];
It is successfully compiled, but I have core dump on start.
It is possible to call malloc
in new
bad it is really bad idea. It is possible to call new(std::nothrow)
but it is bad too.