Question

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;
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top