所念皆山海 2021-08-16 02:01:55 阅读数:412
所謂的棧解退意思是運行結果非常類似於棧的後進先出,代碼示例如下:
#include<iostream>
using namespace std;
class A
{
int x;
public:
A(int x1):x(x1)
{
cout<<"a"<<x<<"被創建"<<endl;
}
~A()
{
cout<<"a"<<x<<"被釋放"<<endl;
}
};
void f1()
{A a1(1);
throw 0;
}
void f2()
{
A a2(2);
f1();
}
void f3()
{
A a3(3);
try
{
f2();
}
catch(int)
{
cout<<"异常被處理"<<endl;
}
A a4(4);
}
int main()
{
f3();
return 0;
}
版权声明:本文为[所念皆山海]所创,转载请带上原文链接,感谢。 https://gsmany.com/2021/08/20210816020110084b.html