Why is CWnd::MessageBox non-const?

Viewed 104

I am getting this compiler error:

Error C2662: CWnd::MessageBoxA : cannot convert this pointer from const CEditField to CWnd &*

In the following const method:

bool CEditField::CanBeChanged() const
{
    bool bCanBeChanged = true;
    // ...
    if (!bCanBeChanged)
    {
        MessageBox("This field is uneditable", "Cannot Edit Field");
    }
    return bCanBeChanged;
}

CEditField is derived from CDialog.

I am working around this by using the WinAPI MessageBox(this->m_hWnd, ...).

Why would CWnd::MessageBox be non-const?

0 Answers
Related