Click here to Skip to main content
15,885,078 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

Can anybody knows the concept of Static destructors in c++.
n what scenario these are being used and how to implement that.

Please guide me.
Thanks in advance.
Posted
Comments
Albert Holguin 24-Feb-11 14:20pm    
The idea of static methods in C++ is based on having methods that are independent of member variables, so since static methods shouldn't be tied to member variables, there's really no such thing as a static destructor.
Andrew Brock 25-Feb-11 3:46am    
A more accurate description would be:
The idea of static methods in C++ is based on having methods that are independent of CLASS INSTANCES, so since static methods shouldn't be tied to AN INSTANCE, there's really no such thing as a static destructor.

Although you are correct, member variables cannot be used without an instance.
Albert Holguin 25-Feb-11 11:57am    
You are right Andrew... :)
Niklas L 26-Feb-11 10:02am    
A more general OO terminology would be Class Methods and Instance Methods. In C++ the class methods are declared with the keyword static, with the only exception being constructors. A member variable is an unspecific term. You can use a class variable without an instance, while an instance variable requires an, well... instance.

There's no such thing as a "static" destructor.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-11 15:50pm    
Sure, 5. I was trying to imagine a possible meaning of "static destructor"... Ha-ha!
--SA
The nearest thing to a "static" destructor would be something like a singleton combined with an object manager - as implemented in ACE - see: ACE__Singleton[^]. This, or something like it, is what people usually are looking for when they think about "c++ static destructor"[^] .

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-11 15:49pm    
Good thinking, my 5, but the Question does not worth your interesting Answer.
--SA
Espen Harlinn 24-Feb-11 16:29pm    
Thank you SAKryukov!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900