我是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进行编译时遇到了同样的错误。
答案 0 :(得分:0)
正如Oli Charlesworth所说,你没有动态分配numberPtr
,因此你不能delete
它。如果您打算在new
进行编码,建议您阅读delete
和C++
以及动态内存分配。