overloading new , new[] , delete, delete[]

Hi all,

i want overload the new,new[],delete and delete[] completely in my project.

project has lot of classes. now it is very difficult overload for each class.

is there any way to overload new , new[], delete and delete[] for project

completely.

Thanks
operator new, operator new[], operator delete, and operator delete[] are special functions which can be replaced (not overloaded) by user-provided functions with matching signatures. Just write them and the C++-supplied new/delete will disappear in any translation unit where your declarations are visible.
Last edited on
Take heed at what Cubbi said.

The functions look like this:
1
2
3
void* operator new(size_t num)          // new
void operator delete(void *ptr)         // delete
void operator delete[](void *ptr)       // delete[] 


http://www.cyberplusindia.com/blog/index.php/2008/10/18/overloading-new-and-delete-operators-in-c/

Edit: fix + link.
Last edited on
we have one problem here..

if i define these functions globally , all the linked library will use this overloaded function..i dont what this behavior.. only my library should use this overloaded function , not library which linked to my library.
It's scope dependent, and you cannot affect libaries that are already compiled.
Topic archived. No new replies allowed.