_BLOCK_TYPE_IS_VALID(pHEAD-> nBlockUse)错误 [英] _BLOCK_TYPE_IS_VALID(pHEAD->nBlockUse) error

查看:547
本文介绍了_BLOCK_TYPE_IS_VALID(pHEAD-> nBlockUse)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++的新手(我最喜欢的node.js和Java,但以前做过一些Python),我正在通过理解指针。以下示例在使用调试符号编译时生成运行时错误。

I'm new to C++ (I'm most comfortable with node.js and Java, but have done some Python before) and am working through understanding pointers. The following example generates a runtime error when compiled with debug symbols.

#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)


b $ b

FWIW,我在VS 2008和2013编译时遇到同样的错误。

FWIW, I've gotten the same error when I've compiled with both VS 2008 and 2013.

推荐答案

p>正如Oli Charlesworth所说,u没有动态分配 numberPtr ,因此你不能 delete 。我建议阅读 new delete 和动态内存分配,如果你打算在 C ++

As Oli Charlesworth said, u did not dynamically allocate numberPtr, therefore you can't delete it. I suggest reading about new and delete and Dynamic Memory Allocation if you intend on coding in C++.

这篇关于_BLOCK_TYPE_IS_VALID(pHEAD-&gt; nBlockUse)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆