Overloading new/delete
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement