Jump to content
  • Advertisement
Sign in to follow this  
Calin

Quick Distructor question (C++)

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

If I have a class Apple and I define my own destructor withiout passing anything inside it, will the compiler use the default destructor or will it consider that I have defined my own destructor and use that even if it is empty? I mean this situation: Apple::~Apple(){ }

Share this post


Link to post
Share on other sites
Advertisement
The compiler in c++ will create 3 things with respect to classes if the programmer doesn't explicitly do it already.

1) A default constructor
2) A copy constructor
3) A destructor.

Also, if you create a constructor which accepts parameters such as...

Apple::Apple( const CColor& colorOfApple )
{
}

...then the compiler will not make a default constructor.

The copy constructor is one of those things that unless you really know what your doing, your probably best leaving to the compiler. It only really needs to be added if you need deep copying of objects.

And onto the destructor...I wasn't aware that you could have parameters passed into the destructor anyway.

Unless marked virtual they will behave exaclty how you would imagin they would behave.

Anyway...hope that cleared up things.

Share this post


Link to post
Share on other sites
The default distructor destroys all member variables.
However I thought if you leave your destructor empty then nothing would be deleted at the end of the application because the destrutor doesn't contain any instruction on how to proceed when the life of the class ends.
I'm not arguing with you SiCrane, I'm just trying to understand how things work.

Share this post


Link to post
Share on other sites
The destructor does whatever is in the body of the destructor and then calls the destructors for all member variables (if any) and then the destructor for all base classes (if any).

Share this post


Link to post
Share on other sites
Quote:

and then calls the destructors for all member variables


I didn't knew this one. Thanks for the clarification.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!