开,用这种模式去处理,但是它不是直接的,简单的亲密支持是最好的办法。 下面是在原始的C++中,你去完成这些事情: //this is a code fragment { try { Foo* f=new Foo(/* params */); //all kinds of code, some of which might throw exceptions delete f; } catch (/* something */) { delete f; //whatever else, or rethrow; } } 如果你在堆栈建立对象,生命期是简单的 //this is a code fragment { Foo f; //all kinds of code, some of which might throw exceptions } 当f超过范围,不论是否是意外它将被清除这是自然的。 当对象在管理堆里时,你不能把它删除,它将被碎片收集清除,如果你想清除管理着源文件的页码:[1] [2] [3] [4] [5] [6] [7] 第3页、共7页 |