I'm programming a linked list and a trie that allows linked lists to be added into it. I've tested my linked list thoroughly, and the destructor works perfectly for any list. However, I'm encountering a strange problem when passing the linked list as a parameter.
The trie has a function addList(List t) . Whenever this function is called in my driver, whether there is code in the function or not, there is a segfault at the very end of the program. I have confirmed that the segfault is occurring because of the List destructor.
Does anyone know why something like this might happen? Why a destructor might suddenly not work when passing the object as a parameter?
Does List::List(const List &) perform a deep copy of the list? It sounds like you might have two Lists with the same internal pointer, and when the second List gets destructed the pointer is already invalid.