删除一个对象两次? [英] deleting an object twice?

查看:70
本文介绍了删除一个对象两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




删除对象多次出现未定义的行为?我认为它不仅仅是确保...谢谢


Rick

Hi,

Does deleting an object more than one times incur undefined behavior? I
think it doesn''t but just making sure... thanks

Rick

推荐答案

Rick写道:



删除一个对象多次出现未定义的行为?


第一次删除会使指针无效。使用

无效指针调用未定义的行为。

我认为它不仅仅是确保...谢谢

Hi,

Does deleting an object more than one times incur undefined behavior?
The first delete renders the pointer to it invalid. Using an
invalid pointer invokes undefined behaviour.
I
think it doesn''t but just making sure... thanks




你错了。

-

Karl Heinz Buchegger
kb ****** @ gascad.at


" Rick" < rrquick @ NOSPAM-COM>在留言中写道

新闻:3f ******** @ clarion.carno.net.au ...
"Rick" <rrquick@nospam-com> wrote in message
news:3f********@clarion.carno.net.au...

删除对象多次出现未定义的行为?我认为它不仅仅是确保...谢谢

Rick
Hi,

Does deleting an object more than one times incur undefined behavior? I
think it doesn''t but just making sure... thanks

Rick




你是否正在设置指针第一次删除后为null?我想你

删除了一个空指针与两次删除指针混淆了。我不确定这是否是标准行为,但是在少数编译器上,

我使用删除检查空指针并且什么也没做。



Are you setting your pointer to null after the first delete? I think you
have deleting a null pointer mixed up with deleting a pointer twice. I am
not sure if this is a standard behavior or not but on the few compilers that
I have worked with delete checks for a null pointer and does nothing.


Rick写道:
Rick wrote:


删除对象多次出现未定义的行为?我认为它不仅仅是确保...谢谢

Rick
Hi,

Does deleting an object more than one times incur undefined behavior? I
think it doesn''t but just making sure... thanks

Rick




确实如此。删除会将指针呈现为无效,因此再次调用delete

将导致未定义的行为。要避免这种情况,只需在删除后将

指针设置为NULL即可。调用删除的NULL指针将无效。


-

Dipl.-Inform。 Hendrik Belitz

电子中心实验室

研究中心Juelich



It does. Delete renders a pointer to be invalid and so calling delete again
will result in undefined behaviour. To circumvent this, simply set the
pointer to NULL after deletion. Calling delete for a NULL pointer will do
nothing.

--
Dipl.-Inform. Hendrik Belitz
Central Laboratory of Electronics
Research Center Juelich


这篇关于删除一个对象两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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