From e30444cdde9544dec44a5a88fe9c8f823df19e36 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 20 Nov 2021 22:57:27 +0000 Subject: (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 --- list.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'list.cpp') 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 *next; + + ~List() + { + if (next == NULL) + return; + delete next; + } }; template -- cgit v1.2.3-13-gbd6f