BUG: Access to Nested Base Class Member Functions Blocked

Last reviewed: April 30, 1997
Article ID: Q167749
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, version 5.0

SYMPTOMS

When a class derived from a nested class calls a base class member function explicitly, the compiler generates error C2352: (relative to the sample code below):

   main.cpp(13) : error C2352: 'A::B::f' : illegal call of non-static
   member function

RESOLUTION

There are 2 workarounds:

  1. Call the member function without the scope resolution operator. This is the simplest workaround, but it will not work if a member function of the same name is defined in the derived class. Please see workaround #1 after the sample code below.

  2. Declare a pointer to member function and call the base class function via the pointer. Please see workaround #2 after the sample code below.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Sample Code

   /* Compile Options: None */
   class A {
   public:
     class B {
     public:
          void f();
     };
   };

   class C : public A::B {
   public:
     void g() { A::B::f(); } // <== C2352 at this line
   };

Workaround #1

Call f() without the scope resolution operator:

   class C : public A::B {
   public:
     void g() { f(); }
   };

NOTE: This will not work if there is a C::f member function defined. If that is the case, use workaround #2.

Workaround #2

Call A::B::f() via a pointer to member function:

   class C : public A::B {
   public:
     void g()
     {
          void (A::B::* fp)() = A::B::f;
          (this->*fp)();
     }
   };
 

	
	


Keywords : CPPLngIss kbprg vcbuglist500 kbbuglist
Version : 5.0
Platform : NT WINDOWS
Issue type : kbbug


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: April 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.