小编Dha*_*raj的帖子

抛出异常时如何清除动态内存?

void a(){
    int *ptr = new int(10);
    throw 1;        // throwing after memory allocation
    delete ptr;
}
int main(){
    try{
        a();
    } catch(...){
        cout << "Exception"<<endl;
    }
 }
Run Code Online (Sandbox Code Playgroud)

这个程序会导致内存泄漏,有没有办法清除分配的动态内存..?

c++ exception-handling

0
推荐指数
1
解决办法
614
查看次数

标签 统计

c++ ×1

exception-handling ×1