FIX: C2248 Error When Calling CView::OnInitialUpdate() (113534)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++, 32-bit Editions 1.0
This article was previously published under Q113534 SYMPTOMS
Attempting to call CView::OnInitialUpdate() from a non-CView derived class
causes the compiler to generate the following error message:
error C2248: 'OnInitialUpdate' : cannot access protected member
declared in class 'CView'
CAUSE
The CView class contains the function OnInitialUpdate(), which is called by
the framework after the view is attached to a document but before the view
is initially displayed. OnInitialUpdate() is declared as a protected member
of the CView class. Protected member functions cannot be accessed by
objects of another class type unless that class is derived from the
protected member function's class or is declared to be a friend of the
protected member function's class.
RESOLUTION
To work around this problem, do one of the following:
- Upgrade to Visual C++ version 1.5. MFC version 2.5 supplied with Visual
C++ version 1.5 for Windows declares the OnInitialUpdate() function as a
public member of the CView class.
-or-
- Use the CWnd::SendMessage function to send a WM_INITIALUPDATE message to
the view. For example:
class CAnotherClass
{
void MemberFunction()
{
CDerivedView * pView = new CDerivedView;
if( pView != NULL )
pView->SendMessage(WM_INITIALUPDATE);
}
};
-or-
- Derive from CView and declare the class where OnInitialUpdate() is being
called from as a friend. For example:
class CDerivedView : public CView
{
friend class CAnotherClass;
public:
virtual void OnDraw(CDC* pDC);
};
-or-
- Derive from CView and override the OnInitialUpdate() member function,
making the override a public member of the derived class. For example:
class CDerivedView : public CView
{
public:
virtual void OnDraw(CDC* pDC);
virtual void OnInitialUpdate(){ CView::OnInitialUpdate(); }
};
STATUS
Microsoft has confirmed this to be a problem in the Microsoft Foundation
Classes (MFC) version 2.0. The problem was corrected in MFC version 2.5 and
MFC version 3.0.
Modification Type: | Major | Last Reviewed: | 11/18/2003 |
---|
Keywords: | kbBug kbDocView kbfix kbVC150fix KB113534 |
---|
|