Template Node class destructors

With regards to a template Node class for a linear linked list, will the list objects dtor (explicit, recursive) correctly deallocate memory used in the Node object, if the data field for the Node holds a pointer to a dynamic char array? Or would I need to write a dtor for the Node?

Showing the actual classes and data members you're talking about would probably help answer your question, but it's actually quite simple on its surface:

- For every new that you call, you need to call delete.
- For every new[] that you call, you need to call delete[].
That's it.

- If a pointer to something you new'd goes out of scope before it's delete'd, that's a memory leak.
- If you are calling new somewhere in your class logic, chances are you're going to want a delete call somewhere in the destructor.
Last edited on
Topic archived. No new replies allowed.