Re: Calling virtual method of base class nested in template class (VC++ 6.0)
 
Actually, I came up with a simpler example that exhibits the same bug (no 
template, and nesting at only a single level):
#include <iostream>
class B
{
public:
  B( ) { }
  class N1
  {
  public:
    N1( ) { };
    virtual void f( )
    {
      std::cout << "B< >::N1::f( )" << std::endl;
    }
  };
};
class D : public B
{
public:
  class N1 : public B::N1
  {
  public:
    N1( ) : B::N1( ) { };
    virtual void f( )
    {
      typedef B::N1 BN1;
      std::cout << "D::N1::f( )" << std::endl;
      BN1::f( );
    }
  };
};
void
main( int argc, char* argv[ ] )
{
  D::N1 n1;
  n1.f( );
}
However, the problem is worked around by changing the name of D::N1 to 
something other than N1.  Apperently, the VC6.0 compiler becomes confused as 
to which N1 I was referring and just assumed the most derived N1, rather 
than the one specified by the typedef (i.e., the N1 in B).
When I renamed N1 to, say, Joe, it worked.
"Roger" <someone@idontwantspam.com> wrote in message 
news:KNWIg.4215$yO7.3921@newssvr14.news.prodigy.com...
Hi all.
Here's a little quandry I've run in to and can't tell if it's a compiler
bug, or if it's bad code.  First, here's the code:
===================================
#include <stdio.h>
template < typename T >
class B
{
public:
 B( ) { }
 class N1
 {
 public:
   N1( ) { };
   class N2
   {
   public:
     N2( ) { };
     virtual void f( )
     {
       printf( " B< >::N1::N2::f( )\n" );
     }
   };
 };
 T _m;
};
class D : public B< int >
{
public:
 class N1 : public B< int >::N1
 {
 public:
   N1( ) : B< int >::N1( ) { };
   class N2 : public B< int >::N1::N2
   {
   public:
     N2( ) : B< int >::N1::N2( ) { };
     virtual void f( )
     {
       typedef B< int >::N1::N2 Bint;  // must do this to avoid VC6.0's 
"error C2352: 'B<int>::N1::N2::f' : illegal call of non-static member 
function" bug.
       printf( " D::N1::N2::f( )\n" );
       // B< int >::N1::N2::f( ) causes the compiler to complain (see 
typedef above).  However, VC7.1 works fine.
       Bint::f( );
     }
   };
 };
};
void
main( int argc, char* argv[ ] )
{
 D::N1::N2 n2;
 n2.f( );
}
==================================
Invoking n2.f( ) causes an infinite loop, dumping out "D::N1::N2::f( )"
ad-nausium.  I am trying to call the base-class f( ) in B::N1::N2, but the 
VC6.0
compiler just generates code that instead calls D::N1::N2::f( ) 
recursively.
VC7.1 compiles this just fine (even on the commented out line).
What am I doning wrong?  Or, is this a compiler bug?
If it's a bug, is there a fix or how can I call the base's f( )?
BTW: I'm stuck w/VC6.0, so please don't suggest using VC7.1; thanks.
Thanks for any help you can offer!
- Roger