J
junw2000
class A
{
public:
A() { p_a = new int;}
~A() { delete p_a; } //Line1
private:
int *p_a;
}
void f()
{
try
{
A a1;
cout << "In f()" << endl;
g(); //Line2
A a2;
}
catch()
{
cout << "In catch" << endl;
}
}
void g()
{
cout << "In g()" << endl;
throw; //Line3
}
When an exception is thrown at Line3 in g(), stack will unwind at
Line2 in f(). When a1 is destructed, will Line1 be excecuted so that
p_a is deleted? How about a2?
Thanks.
}
{
public:
A() { p_a = new int;}
~A() { delete p_a; } //Line1
private:
int *p_a;
}
void f()
{
try
{
A a1;
cout << "In f()" << endl;
g(); //Line2
A a2;
}
catch()
{
cout << "In catch" << endl;
}
}
void g()
{
cout << "In g()" << endl;
throw; //Line3
}
When an exception is thrown at Line3 in g(), stack will unwind at
Line2 in f(). When a1 is destructed, will Line1 be excecuted so that
p_a is deleted? How about a2?
Thanks.
}