FIX: C2248 Error When Calling CView::OnInitialUpdate()

Last reviewed: September 18, 1997
Article ID: Q113534
1.00    | 1.00
WINDOWS | WINDOWS NT kbprg kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft Visual C++ for Windows, versions 1.0
        - Microsoft Visual C++ 32-bit Edition, version 1.0
    

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.

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.

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(); }
          };
    


Additional reference words: 1.00 2.00 2.10 CScrollView CFormView
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: MfcDocView


Keywords : MfcDocView kbbuglist kbfixlist kbprg
Technology : kbMfc
Version : 1.00 | 1.00
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.