0xC0000005: 读取位置 0xbaadf02d 时发生访问冲突
时间:2008-05-13 21:41:42
来源:论坛整理 作者: 编辑:chinaitzhe
{
if(i>length ¦ ¦i <=0)
{
cout < <"error getpos!" < <endl;
return false;
}
else
{
node *p=new node;
p=head->next;
for(int j=1;j <i;j )
p=p->next;
x=p->value ;
delete p;
cout < <"success getpos" < <endl;
return true;
}
}
我在vs2005的vc 中,一执行到x=p-〉value这句,就中断,找不到解决方法。
网友回复:
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ for(int j=1;p&&j <i;j ) //加一个p&&,不然就会出问题 p=p->next;
网友回复:第一个if不是已经判定过有多少个node了么?怎么p还会是null
网友回复:node *p=new node;
p=head->next;
——怎么刚申请的空间就直接丢弃了?
网友回复:
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ //刚才没有看清楚,应该是这样 node *p=head->next; for(int j=1;j <i;j ) p=p->next; x=p->value ; cout <<"success getpos" <<endl;
网友回复:
不明白为什么把delete p去掉啊,p不是已经没有用处了么
网友回复:可能和你的length有关,你的length包含head否?
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ node *p=head; while(i--) p=p->next; x=p->value ; cout <<"success getpos" <<endl;
网友回复:node *p=head->next;
for(int j=1;j <i;j )
p=p->next;
x=p->value ;
cout < <"success getpos" < <endl;
改成以上了,可还是在x=p-〉value处中断,请大家再帮忙看看,谢谢。
网友回复:在只有head节点的时候length应该是0,
在有一个节点的时候p首先指向第一个节点(head->next),i=1时循环零次,然后访问value,没有问题
网友回复:还是不行~~~~
网友回复:跟踪一下p的值
网友回复:
早上代码早解决
扭扭捏捏慢慢吹
网友回复:貌似程序逻辑有问题啊
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ bool mylist::getpos(int i,myvalue &x) { if(i>length || i <=0) { cout <<"error getpos!" < <endl; return false; } else { node *p=new node; // 刚分配的内存 p=head->next; // 马上就丢掉了?!! for(int j=1;j <i;j ) // 这里飞雪已经说了 // 另一个问题,虽然不知道你的 length 和 i 的具体含义, // 但这里的循环条件应该还是有问题。 // 假如 length 为 1,那 i 的有效值又会是多少?j 从 1 到 i - 1 能找到目标节点吗? p=p->next; // 另外,假如你的程序逻辑正确,依靠 length 不判定 p 也可以, // 但很明显,你的程序还存在其它的问题 x=p->value ; delete p; // 那这里又 delete 的是什么?!! cout < <"success getpos" < <endl; return true; } }
网友回复:node *p=new node;
p=head->next;
/*
嗯?
是不是应该
node *p = new node;
p->next = head
*/
关键字:xC,读取,位置,xbaadf,发生,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面