Here I have called destructor explicitly , but it is not destroying object. In show function I have destroyed the object but still I am able to access show2() ,How ?
class Test{
public:
Test() {
cout<<"constructor\n";
}
Test(const Test&t) {
cout<<"Copy constructor\n";
}
~Test() {
cout<<"Destructor\n";
}
void show() {
cout<<"Show Begin\n";
this->~Test();
cout<<"Show End\n";
}
void show2() {
cout<<"Show2 Begin\n";
this->Test::~Test();
cout<<"Show2 End\n";
}
};
int main() {
Test t;
t.show();
t.show2();
return 0;
}
Output
constructor
Show Begin
Destructor
Show End
Show2 Begin
Destructor
Show2 End
Destructor