diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-11-20 22:57:27 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-11-20 22:57:27 +0000 |
commit | e30444cdde9544dec44a5a88fe9c8f823df19e36 (patch) | |
tree | d5be818f19a7b743be13ae6f39d45b932a3944b2 | |
parent | cae91a793cec40e20d1fbe12b07caf9d5018490c (diff) | |
download | algorithms-e30444cdde9544dec44a5a88fe9c8f823df19e36.tar.gz algorithms-e30444cdde9544dec44a5a88fe9c8f823df19e36.tar.bz2 algorithms-e30444cdde9544dec44a5a88fe9c8f823df19e36.zip |
(list)+destructor function in struct
Nice feature of C++, destructors make it kinda nice to do memory
management. Though they don't fully reduce the pain lol
-rw-r--r-- | list.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -12,6 +12,13 @@ struct List { T value; struct List<T> *next; + + ~List() + { + if (next == NULL) + return; + delete next; + } }; template <typename T> |