Debug Assertion Failed! File: dbgdel.cpp Line: 47 _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: D:\dev\out\test.exe
File: dbgdel.cpp
Line: 47
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
中止(A)   重试(R)   忽略(I)
---------------------------

原因找到了。PTCHAR test = new TCHAR[1024]之后使用了test++之类的语句后delete[] test。 这样delete指向的并非test的头。所以报错。可以在new完之后用一个PTCHAR来保存head pointer: testHead = test。 然后delete[] testHead。

发表评论

电子邮件地址不会被公开。 必填项已用*标注