Advertisement

Classes and the destructor

Started by July 27, 2000 06:18 PM
5 comments, last by +AA_970+ 24 years, 4 months ago
When an app exits the destructor is automatically called on all classes, right? +AA_970+
Ah come on i know there are a ton of C++ programmers here.

If i have something like:

CSprite Test_Sprite1;

where CSprite is a class,

Do i have to call the destructor (Test_Sprite1.~CSprite), which is used to clean up some stuff from memory, or is it automatically called when the application exits?

BTW, i did some tests and i think the destructor is called when the app exits, i just want to make sure.

+AA_970+

Edited by - +AA_970+ on July 27, 2000 10:49:48 PM
Advertisement
You are correct, the class deconstructor is automatically called, you should never call it yourself.

Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
Thanx Alot

+AA_970+
Although it doesn''t do anything horrible if you call the destructor yourself. It''s just a matter of "style" not to call it. There may be situations where it''s necessary but I''ve never come across one.
yes it''s automatically called, but if you ever need to test if a function is called just put a simple text out in it to say something like "myFunction() called" or something....

40

www.databyss.com
www.omlettesoft.com

"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
-40
Advertisement
I just want to clarify something...

If the class instance is global then the destructor is called when the program is exited, right?

And if the class instance is local to a function the destructor is called when the function is exited? Right again?

But if the function is static - is the destructor still called on a local class instance?

jumble
-----------
Microsoft patents ones and zeroes - remind you of Hasbro?
jumble-----------

This topic is closed to new replies.

Advertisement