可能重复:
可以在其范围之外访问局部变量的内存吗?
代码:
#include <iostream>
using namespace std;
class B{
public:
int b;
B():b(1){}
~B(){cout << "Destructor ~B() " << endl;}
};
class A{
public:
B ob;
A()try{throw 4;}
catch(...){cout << "Catched in A() handler : ob.b= " << ob.b<<endl;}
};
int main()try{
A t;
}
catch(...){cout << "CATCHED in Main" << endl;}
输出:
Destructor ~B()
Catched in A() handler : ob.b= 1
CATCHED in Main
我的问题是如何访问其析构函数调用完成b
的对象的成员变量。ob