Send to a Friend

HeroicZach's avatar

Is it possible to return an entire linked list object from a method in C++ without running the destructor?

Asked by HeroicZach (195points) October 8th, 2009

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?

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.