Clarification of Destructors in C++ class's
If I am not mistaken, I don't think it's called automatically.
You have to called "delete" or else you will get a dangling pointer which leads to memory leak.
You have to called "delete" or else you will get a dangling pointer which leads to memory leak.
I forgot to mention one thing.
The destructor can be called automatically when the pointer is out of scope if the pointer is an auto_ptr type.
This is the template spec for auto_ptr:
template <class T> class auto_ptr
It is declared in the header <memory>
But auto_ptr does not support reference couting, so the pointer can have only 1 owner at a time.
Hope that helps
The destructor can be called automatically when the pointer is out of scope if the pointer is an auto_ptr type.
This is the template spec for auto_ptr:
template <class T> class auto_ptr
It is declared in the header <memory>
But auto_ptr does not support reference couting, so the pointer can have only 1 owner at a time.
Hope that helps
He didn't say anything about pointers. Assuming
then the answer is indeed yes.
{ MyClass bar; // bar.~MyClass() gets invoked automatically here. }
then the answer is indeed yes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement