C++ Destructors

Are destructors in a class only required if you specifically allocate memory using new inside the class?

For example, let's say I am making an ordered Linked List and I put all the functions, such as insertNode and deleteNode, inside the class. Since I would need to allocate memory inside the class, I would also put a destructor in the class.

However, let's say instead, that the functions such as insertNode and deleteNode are not a part of the class, but are rather defined outside of the class. Therefore, I would not need to use "new" inside the class. Would I still need a destructor?
Last edited on
These days one is encouraged to use unique_ptr or scoped_ptr to hold dynamically allocated objects within classes, making the need for explicit destructors even more of a rarity.

That said, there are other system resources besides memory that a class may be managing. If you are managing any system resources whose lifetimes you are responsible for, you will generally have to clean them up in a destructor.
Thanks
Topic archived. No new replies allowed.