【发布时间】:2014-01-20 19:48:03
【问题描述】:
我正在查看 wxWidgets hello world 和示例:http://www.wxwidgets.org/docs/tutorials/hello.htm 和 http://www.wxwidgets.org/docs/tutorials/hworld2.txt 和 http://zetcode.com/gui/wxwidgets/firstprograms/
和其他链接..
我注意到他们有:
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( _("Hello World"), wxPoint(50, 50), wxSize(450, 340) );
frame->Show(true);
SetTopWindow(frame);
return true;
}
和
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_About, _("&About...") );
menuFile->AppendSeparator();
menuFile->Append( ID_Quit, _("E&xit") );
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, _("&File") );
SetMenuBar( menuBar );
CreateStatusBar();
SetStatusText( _("Welcome to wxWidgets!") );
}
这些sn-ps,教程,链接都没有使用删除! 怎么会这样?他们为什么不删除一个东西?
他们在做什么我只是没看到?也许以某种方式覆盖“新”并以某种方式自动删除?
有什么诀窍?
【问题讨论】:
-
他们显然将这些实例传递给其他函数(根据他们的名字,他们现在是负责相关对象的人。)事后删除它们会让其他函数不开心,说最少。
标签: c++ memory-management c++11 wxwidgets