Linked List copy constructor

I've always been bad with copy constructors with linked lists, and I need help with this one. Each node has m_data (the value contained in the node) and m_next (a pointer to the next node). m_head is a pointer to the head node, which is a dummy node. When printing the results of this copy constructor, it prints nothing.



What I've found through debugging is that it's copying each node into f just fine, but for some reason it's not changing the host object at all. All the copies just stay in f while the host linked list remains empty. I'm clearly doing something wrong in this copy constructor, any ideas what?
Last edited on
You never set m_head's m_next pointer to anything other than NULL. All of the nodes allocated in the loop are leaked.
Last edited on
Thanks so much! Was able to fix it thanks to that. I keep expecting pointers to do things they can't.
Last edited on
Topic archived. No new replies allowed.