Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Destructors with wxWidgets

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Destructors with wxWidgets
#4572
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?

Eric
Message2. Re: Destructors with wxWidgets
#4619
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
#4622
Posted by: upCASE 2004-06-25 14:52:59
Hi!
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..

upCASE
-----------------------------------
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
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sun 2022-12-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0