Jump to content
  • Advertisement
Sign in to follow this  
webjeff

Overloading new/delete

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!