Jump to content
  • Advertisement
Sign in to follow this  
ender_341

Clarification of Destructors in C++ class's

This topic is 4956 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

Advertisement
If I am not mistaken, I don't think it's called automatically.

You have to called "delete" or else you will get a dangling pointer which leads to memory leak.

Share this post


Link to post
Share on other sites
I forgot to mention one thing.

The destructor can be called automatically when the pointer is out of scope if the pointer is an auto_ptr type.

This is the template spec for auto_ptr:

template <class T> class auto_ptr

It is declared in the header <memory>

But auto_ptr does not support reference couting, so the pointer can have only 1 owner at a time.

Hope that helps

Share this post


Link to post
Share on other sites
He didn't say anything about pointers. Assuming


{
MyClass bar;

// bar.~MyClass() gets invoked automatically here.
}


then the answer is indeed yes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!