Microsoft KB Archive/167749

From BetaArchive Wiki
Knowledge Base


Article ID: 167749

Article Last Modified on 12/8/2003



APPLIES TO

  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++ 6.0 Standard Edition



This article was previously published under Q167749

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

In the definition of the derived class, use typedef to define an alias for the base class (see the sample code), and use this alias to qualify calls to the base class methods.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.


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
Use a typedef for class A::B as follows:


class C : public A::B 
{
   public:
      typedef A::B BaseClass;
      void f() { BaseClass::f(); } // <== No Error Any More
};
                

Keywords: kbbug kbfix kbnoupdate kblangcpp kbprogramming KB167749