Is it possible to return an entire linked list object from a method in C++ without running the destructor?
Basically I’m designing a C++ class where one of the class functions has it return another object of that same class (return myClass;). This class uses dynamic memory management (linked lists) in order to function properly.
When C++ returns the class, it’s really only returning the head reference, then, when it runs the destructor after the class function exits, it deletes all the nodes to which the head is linked.
Is there any way to really do this right?
This question is in the General Section. Responses must be helpful and on-topic.