Guidance Forums / wxWidgets (wxWindows) in C++ / Destructors with wxWidgets

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Destructors with wxWidgets
Posted by: Nightfox 2004-06-22 15:30:02
I have a question..  I read somewhere in the wxWidgets documentation that you can (and should) use the 'new' operator to create your controls, and when the application quits, the wxWindows classes will free the memory used by the controls you create with 'new'.  My question is then, when you have a class that makes use of some controls in this fashion, is it necessary (or even desirable) to declare a destructor?  A thought ran across my mind that if you declare a destructor, it would basically be over-riding the parent class's destructor, so that it might not actually free the resources that you create with 'new'?  Or am I incorrect?

Message2. Re: Destructors with wxWidgets
Posted by: guidance 2004-06-25 06:51:49
I understand that all widgets with "parent" parameters are managed by wxW automatically, because these parents know who is their children, so, for you, it's not necessary to worry about deleting/destroying them. In the mean time, by viewing samples, I believe other wxW objects, especially non-GUI related, need to be deleted by yourself.
Message3. Re: Destructors with wxWidgets
Posted by: upCASE 2004-06-25 14:52:59
Correct! The magic is that the new operator is overloaded for all wxObject/wxWindow derived classes. So the framework knows which object have to be destroyed. Writing a destructor doesn't harm this process since I believe that the framework itself calls the destructors of the objects. Still, there are some objects you'd have to delete yourself, like when you create a wxString on the heap etc..

If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Thu 2024-6-20  Guidance Laboratory Inc. Hits:0