When should I create a destructor?
For example: public class Person { public Person() { } ~Person() { } } When should I manually create a destructor? When have you needed to create a destructor? 7 Answers 7
For example: public class Person { public Person() { } ~Person() { } } When should I manually create a destructor? When have you needed to create a destructor? 7 Answers 7
What is the use of having destructor as private? 9 Answers 9
Most people say never throw an exception out of a destructor – doing so results in undefined behavior. Stroustrup makes the point that “the vector destructor explicitly invokes the destructor for every element. This implies that if an element destructor throws, the vector destruction fails… There is really no good way to protect against exceptions … Read more
When overriding a class in C++ (with a virtual destructor) I am implementing the destructor again as virtual on the inheriting class, but do I need to call the base destructor? If so I imagine it’s something like this… MyChildClass::~MyChildClass() // virtual in header { // Call to base destructor… this->MyBaseClass::~MyBaseClass(); // Some destructing specific … Read more
class Package: def __init__(self): self.files = [] # … def __del__(self): for file in self.files: os.unlink(file) __del__(self) above fails with an AttributeError exception. I understand Python doesn’t guarantee the existence of “global variables” (member data in this context?) when __del__() is invoked. If that is the case and this is the reason for the exception, … Read more
Is there a destructor for Java? I don’t seem to be able to find any documentation on this. If there isn’t, how can I achieve the same effect? To make my question more specific, I am writing an application that deals with data and the specification say that there should be a ‘reset’ button that … Read more