• Advertisement

Archived

This topic is now archived and is closed to further replies.

classes, parameters and destructors

This topic is 5121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you pass a class to a function and not set off the destructor when the function is complete? I am passing a homemade string class with a destructor that destroys the string pointer. So it seems to me that it is creating a new class and then destroying the original when it goes out of scope.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by squicklid
I am passing a homemade string class with a destructor that destroys the string pointer. So it seems to me that it is creating a new class and then destroying the original when it goes out of scope.

It sounds like you need to define a copy constructor and an assignment operator. The "rule of three" states that if you need a destructor, an assignment operator, or a copy constructor, you probably need all three.

Of course, passing the string by reference will be more efficient.

EDIT: Oh, and SiCrane is referring to allocation through the use of the new keyword.


"Sneftel is correct, if rather vulgar." --Flarelocke

[edited by - sneftel on April 15, 2004 4:04:17 AM]

Share this post


Link to post
Share on other sites

  • Advertisement