Microsoft KB Archive/113534

= FIX: C2248 Error When Calling CView::OnInitialUpdate =

Article ID: 113534

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.0 Professional Edition 

-



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.

<div class="resolution_section">

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-

</li>  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-

</li>  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-

</li>  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; } };                       </li></ul>

<div class="status_section">

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.

Additional query words: 1.00 2.00 2.10 CScrollView CFormView

Keywords: kbbug kbfix kbvc150fix kbdocview KB113534

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.