_BLOCK_TYPE_IS_VALID(pHEAD-> nBlockUse)错误

时间:2014-06-10 21:04:02

标签: c++ visual-studio visual-studio-2008 visual-studio-2013

我是C ++的新手(我对node.js和Java最熟悉,但之前已经完成了一些Python)并正在通过理解指针。以下示例在使用调试符号进行编译时生成运行时错误。

#include <iostream>

void main(){
    int number = 0;
    int * numberPtr = &number;
    * numberPtr = 1;

    std::cout << number;
    delete numberPtr;
}

错误信息:

Debug Assertion Failed!

Program: C:\path\to\executable\main.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp

Expression: _BLOCK-TYPE_IS_VALID(pHead->nBlockUse)

FWIW,我在使用VS 2008和2013进行编译时遇到了同样的错误。

1 个答案:

答案 0 :(得分:0)

正如Oli Charlesworth所说,你没有动态分配numberPtr,因此你不能delete它。如果您打算在new进行编码,建议您阅读deleteC++以及动态内存分配。