Destructor is used to destroy(release) the Memory which is allocated to object. And it can be called explicitly. In the follwoing code the destructor for objA is called. After that the member of objA is accessed. How can it be possible if the destructor released the memory of objA?


Code: C
#include<iostream.h>
class A
{
    public:
 int a;
 A()
 {
     a=10;
     cout<<"in constructor\n";
 }
 ~A()
 {
     cout<<"in destructor\n";
 }
};
main()
{
    A objA;
    cout<<"a ="<<objA.a<<"\n";
    objA.~A();
    cout<<"a ="<<objA.a<<"\n";
    return 1;
  }

Output :
in constructor
a =10
in destructor
a =10
in destructor

Last edited by SaswatPadhi; 9Jul2009 at 17:34.. Reason: Changed from PHP to C Code Tag