To detect a memory leak, the new keyword is redefined. This is normal if I use [Type 1]. But a compilation error occurs if I uncomment [Type 2]. Is there a way to use both types of new ones?
#include <crtdbg.h> #define new new(_CLIENT_BLOCK, __FILE__, __LINE__) struct Foo { int m_N; Foo() : m_N( 0 ) {} }; int main( int argc, char* argv[] ) { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); _CrtSetReportMode(_CRT_WARN , _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); int* pI = new int( 1 ); delete pI; Foo* pFoo = new Foo; // [Type 1] //Foo* pFoo2 = new (pFoo) Foo(); // [Type 2] return 0; }
c ++ new-operator
codevania
source share