Article ID: 153801 - Last Review: December 8, 2003 - Revision: 2.0

BUG: C2352 Error for Reference to Nested Class Member

This article was previously published under Q153801

On This Page

Expand all | Collapse all

SYMPTOMS

When you attempt to build the sample code below, you will get an error message similar to the following:
error C2352: 'A::AA::m' : illegal call of nonstatic member function

CAUSE

This behavior occurs because you are attempting to access a member of a nested class that has been used as a base class. It is valid to do this. The compiler should not be reporting an error, and, in this case, the error that is being reported is misleading.

RESOLUTION

To work around the problem, you can use a typedef to refer to the nested class that is being used as a base class. This is illustrated in 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 problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Sample Code

/* Compile options needed: none
*/ 
				
The following code reproduces the problem:
   class A
   {
   public:

       class AA
       {
       public:
           void m();
       };
   };

   class B : public A::AA
   {
   public:
       void m() { A::AA::m(); }
   };

   void main()
   {
       B b;
   }
				
The following code works around the problem (note the use of the typedef):
   class A
   {
   public:

       class AA
       {
       public:
           void m();
       };
   };

   typedef A::AA NestedBase;

   class B : public NestedBase
   {
   public:
       void m() { NestedBase::m(); }
   };

   void main()
   {
       B b;
   }
				

APPLIES TO
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
Keywords: 
kbbug kbcompiler kbcpponly kblangcpp KB153801
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations