aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-11-20 22:57:27 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-11-20 22:57:27 +0000
commite30444cdde9544dec44a5a88fe9c8f823df19e36 (patch)
treed5be818f19a7b743be13ae6f39d45b932a3944b2
parentcae91a793cec40e20d1fbe12b07caf9d5018490c (diff)
downloadalgorithms-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.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/list.cpp b/list.cpp
index da9ad4f..873dfe9 100644
--- a/list.cpp
+++ b/list.cpp
@@ -12,6 +12,13 @@ struct List
{
T value;
struct List<T> *next;
+
+ ~List()
+ {
+ if (next == NULL)
+ return;
+ delete next;
+ }
};
template <typename T>