Overloading new/delete

Started by
3 comments, last by Gage64 15 years, 10 months ago
Hi, I'm having some issues overloading new/delete using a gcc compiler. I'm linking with a library which implements the default new/delete. However, when I overload new/delete in my cpp file, no one seems to be going there for new's/delete's. Since it's not in another library, I can't just change the link order. Any ideas on how to get my application using my version of new/delete? Thanks Jeff.
Advertisement
I had a similar problem when I tried to overload the new/delete operators while including DirectX's headers afterwards. DirectX had their own version of the overloaded operators which was overriding mine. Check to see if you are not including any headers that are overloading those same operators.
------------Anything prior to 9am should be illegal.
Check the include order. To ensure that you use the correct new/delete, typically my rule is that the source files should be the only ones including the new definitions but if they aren't then just make sure you include those last.

For example

newdelete.h
-undefs and defines new and delete

File1.cpp
#include ...
#include ...
#include ...
#include "newdelete.h" <- last include


If you do need to use new and delete in a header (for inline functions), consider if its the best idea. It may enforce a strict usage of that file (i.e can't include from anywhere with fully known behaviour) because your newdelete.h file will override the previously defined one which may not be the desired behaviour following your include.
www.ice-d.com
slip,

Thanks for the info... when you say "undefs and defines new and delete". How do you undef new/delete? When I put my overloaded new/delete in a header file, my compiler does not like it. Says expected ";" after the word operator.

Hmmm, any ideas on that?

Thanks!
Jeff.
Take a look here.

This topic is closed to new replies.

Advertisement