請參見下面的代碼和它的輸出 - 請解釋我的代碼異常處理代碼,請解釋一下
void abc(int);
class A
{
public:
A()
{
cout<<"Constructor Called";
}
~A()
{
cout<<"Destructor called";
}
};
int main()
{
try
{
abc(-1);
}
catch(int p)
{
cout<<p<<endl;
}
return 0;
}
void abc(int p)
{
A * Aptr = new A[2];
if(p<0)
throw p;
}
輸出:
Constructor Called
Constructor Called
-1
任何人都可以解釋爲什麼析構函數沒有被稱爲在正常堆疊展開的情況下
而典型的解決方案是? – 2009-10-30 16:32:30