overloading new and delete

白昼怎懂夜的黑 提交于 2019-12-04 16:49:01

I solved this a while ago.

What is happening is that the word new is a macro by the time you get to your overloads (granted, it didn't solve our linking problems) but try adding:

#undef new

after the last include directive in your file but before the first new overload.

edit

This happens because stdafx.h (or something else includes a file that defines DEBUG_NEW) is included before you include your memory leak detection code in some CPP file (you should be able to figure out which from the compiler errors). Thus new has been defined as a macro which causes your compiler to barf at the definition.

to find where xlocale is getting included. just changethe name of xlocale to something else. try to compile and you will see where it fails

In Visual Studio, debug builds of programs already use a 'debug heap', so your own instrumentation is unnecessary.

Using the debug features of your platform, you could for example call _CrtDumpMemoryLeaks at the end of your program, without actually overloading everything.

You are defining the very same overload that Microsoft defines for their own debugging, and running into theirs. I recommend adding an extra dummy parameter to your operator.

I also recommend debugging this not in stdafx.h before putting it there.

Trying to debug this way with std lib is not really going to work out. It won't catch all (or any) of the memory allocation. It's just one of a million reasons not to use std lib, stl, or boost.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!