manish bhatia wrote:
> Hi,
> 
> How come I am seeing destructor getting called twice in the following code?
> 
> struct A 
> { 
>      A() { 
>         cout << "A()\n"; 
>      } 
>      ~A() { 
>         cout << "~A()\n"; 
>      } 
> };
> int main()
> {
>      try {
>         throw A();
>      } catch (const A& a) {
>         cout << "caught\n"; 
>      }
> } 
>  
> Output:
>  
> A()
> ~A()
> caught
> ~A()
> 
> Tried on codepad.org

It might help you if you display the value of the 'this' pointer in your 
'cout'.  That way you can see what is going on better.  One of those 
destructor calls is probably a temporary object that was created.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to