【发布时间】:2019-06-17 19:34:30
【问题描述】:
我只是想知道,如果在释放 new 运算符分配的内存之前发生异常会发生什么?是不是发生了内存泄漏问题?
#include <iostream>
#include<new>
using namespace std;
void func()
{
try
{
int *p = new int[10];
/*
Number of lines code here
.
.
.
.
.
Suppose here I got exception then What heppens????
.
.
.
.
*/
delete []p;
}
catch(const std::exception& e)
{
cout<<"Exception occured"<<endl;
}
}
int main() {
func();
return 0;
}
【问题讨论】:
标签: c++ new-operator free dynamic-memory-allocation