Вопрос

Possible Duplicate:
Should “delete this” be called from within a member method?

Is is correct to call delete from OnOk event handler function, as in the code below.

void CTestDlg::OnOK() 
{
    CDialog::OnOK();

    this->DestroyWindow();
    delete this;
}
Это было полезно?

Решение

I presume you're trying all that because the dialog instance is modeless?

In that case you shouldn't be calling the base class OnOK() from your override, but only DestroyWindow().

If you have to delete this then an override of PostNcDestroy() is the appropriate place.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top