C++: why it doesn't call a destructor?
I use extra brackets in my code. I thought when the destructor should be
called after the local variable scope is ended but it doesn't work like
this:
class TestClass {
public:
TestClass() {
printf( "TestClass()\n" );
}
~TestClass() {
printf( "~TestClass()\n" );
}
};
int main() {
int a, b, c;
{
TestClass *test = new TestClass();
}
}
It outputs:
TestClass()
So it doesn't call the destructor of the TestClass but why? If I call it
manually (delete test) it calls the destructor, right. But why it doesn't
call the destructor in the first case?
No comments:
Post a Comment