void Mainframe::OnClearNotebook( wxCommandEvent& e )
{
int end = m_notebook->GetPageCount();
for ( int i = 0; i < end; i++ )
{
if ( m_notebook->GetPageText( i ) != "Server Log" )
{
m_notebook->DeletePage(i);
}
}
}
此代码在此表单中崩溃,并显示消息“m_notebook->GetPageText() index out of range”;
如何正确遍历所有页面?
编辑,解决方案:
void Mainframe::OnClearNotebook( wxCommandEvent& e )
{
while ( m_notebook->GetPageCount() > 1 )
{
int end = m_notebook->GetPageCount() - 1;
if ( m_notebook->GetPageText( end ) != "Server Log" )
{
m_notebook->DeletePage(end);
}
else
{
break;
}
}
}