⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_17926.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:17926 发表者:zxc 发表日期:2002-10-16 16:46:40
<br>主题:指针问题!
<br>内容:首先定义一个指针:double *dMatrix;<BR>由于多处要用到dMatrix,而且每处的dMatrix的大小和内容不一样!所以我在每次用之前<BR>判断:<BR>if(dMatrix!=NULL)<BR>delete []dMatrix;<BR>dMatrix=new double[dMatrixsize];<BR>然后给dMatrix付值;但程序编译时无错,无警告!但运行时出现:Please enter the path for:DBGHEAP.C 。取消后,出错!<BR>对不起:徐!刚才我没有把问题说清楚!<BR>敬请各位指点!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:iwill 回复日期:2002-10-16 16:50:19
<br>内容:double *dMatrix=NULL;<BR><BR>定义指针一定要初始化,切记切记!!!<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:胡言 回复日期:2002-10-16 16:53:47
<br>内容:delete []dMatrix;<BR>dMatrix = NULL;<BR>应成对出现,否则dMatrix就成野指针了<BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:CDMA2000 回复日期:2002-10-16 16:54:11
<br>内容:注意:用delete删除指针所指的内存后,指针并不等于NULL,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;而是指向一个随机的地址<BR>所以你用这句<BR>&nbsp;&nbsp;if(dMatrix!=NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp; delete []dMatrix;<BR>来判别指针不对,因为你即使调用了delete []dMatrix;<BR>dMatrix不等于NULL<BR>所以你再下次用if(dMatrix!=NULL)永远成立<BR><BR>因此,你再delete []dMatrix;后马上要这样dMatrix=NULL;<BR>即:<BR>&nbsp;&nbsp;if(dMatrix!=NULL)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp; delete []dMatrix<BR>&nbsp;&nbsp;&nbsp;&nbsp; dMatrix=NULL;<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:zxc 回复日期:2002-10-16 17:08:18
<br>内容:谢谢楼上三位!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -