以下のコードはメモリリークを示していますか?C++クラスのコンストラクタで例外をスローする
Testクラスのデストラクタは呼び出されず(画面に出力は表示されません)、Intクラス配列に割り当てられたすべてのメモリがシステムに戻されていないと仮定しますか?私の仮定は正しいのですか?例外が発生した場合、コンストラクタに割り当てられたリソースをどのように返還する必要がありますか?
#include <iostream>
using namespace std;
class Int{
public:
int v;
Int(){
cout<<"inside Int constructor ..."<<endl;
}
~Int(){
cout<<"inside Int destructor ..."<<endl;
}
};
class Test{
public:
Int* a;
Test(){
a=new Int[10];
cout<<"inside Test constructor ..."<<endl;
throw(0);
}
~Test(){
delete [] a;
cout<<"inside Test destructor ..."<<endl;
}
};
int main(){
try{
Test T;
}
catch (int e){
cout<<"Error!!!"<<endl;
}
return 0;
}