Sign-up....

一天内碰到很多次这个错误,为什么?

在编译和连接的时候正常,在运行的时候:

the instruction at "0x0041ea26" referenced memory at "0x00000d008".the memory could not be "read".

碰到很多次,谢谢有经验的大哥介绍一下。

平台:visual studio .net 2003 english version,windows 2k3 english version,win32 project,unmanaged code.

[241 byte] By [msdn] at [2007-8-14 12:57:46]
# 1 Re: 一天内碰到很多次这个错误,为什么?

对不能读的地址空间进行读操作。

一般而言是指针未被始化造成的。

int *p;

cout<<*p;

就可能引起以上错误,因为p未指定确切地址,

可能指向了一个不能读的区域,如系统内存区或代码段。

xteaj at 2004-10-6 9:46:56 >
# 2 Re: 一天内碰到很多次这个错误,为什么?

应该属于段错误

访问了不该访问的段内存吧

kobefly at 2004-10-6 9:59:10 >
# 3 Re: 一天内碰到很多次这个错误,为什么?

刚才调试了一下,好像是delete的问题:

int ia[8]={8,34,3,13,1,21,5,2};

vector<int>vec(ia,ia+8);

ofstream ofil("data.txt");

///....some operation

delete ofil;

delete [] ia;

delete &vec;

三个delete语句无论哪一个都会造成assertion failed,看了msdn的assertion,还是不明白,asser只是做检查,为什么会这样呢?期待高手解答,谢谢。

BestSky at 2004-10-6 10:02:19 >
# 4 Re: 一天内碰到很多次这个错误,为什么?

ofil,ver,ia又不是new出来的,要你delete干什么?

只有new出来的才需要delete

icecools at 2004-10-6 11:39:08 >
# 5 Re: 一天内碰到很多次这个错误,为什么?

你不会以为所有的变量都要delete吧?!

那错误就大了................

icecools at 2004-10-6 11:39:48 >
# 6 Re: 一天内碰到很多次这个错误,为什么?

谢谢各位,明白了只有new创建的object才需要delete,我原来以为只要是创建的指针就一定要delete呢

BestSky at 2004-10-6 16:34:50 >
# 7 Re: 一天内碰到很多次这个错误,为什么?

delete是对堆中的指针而言的

newegg2002 at 2004-10-6 18:16:28 >

C/C++

All Classified