Re: [問題] C++ FQA 文章中,有關 dangling refere …

看板C_and_CPP (C/C++)作者 ( )時間16年前 (2009/02/23 20:11), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《zlw (洞房不敗)》之銘言: : ------------------------------------------------------------------------------ : For example, a wide class of bugs comes from accessing : dangling references - references to objects which were already destroyed. : If a reference is the object, or just another name for it, how can that happen? : ------------------------------------------------------------------------------ : 我知道 dangling pointer 的意思以及怎樣才會發生。 : 但上面說的這個 dangling reference 導致的 bug 要怎樣才能重現我無法理解。 int main() { int *ptr = new int; int &ref = *ptr; delete ptr; ref = 10; ... } -- Ling-hua Tseng (uranus@tinlans.org) Department of Computer Science, National Tsing-Hua University Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design Researching: Software pipelining for VLIW architectures Homepage: https://www.tinlans.org -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.104.77
文章代碼(AID): #19ef9lUx (C_and_CPP)
文章代碼(AID): #19ef9lUx (C_and_CPP)