Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Calling virtual method of base class nested in template class

View Parsed - Show only message text

Path: g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 28 Aug 2006 17:10:14 -0500
Return-Path: <cppm...@netlab.cs.rpi.edu>
To: (Usenet)
From: "Roger" <some...@idontwantspam.com>
Newsgroups: comp.lang.c++.moderated
Subject: Calling virtual method of base class nested in template class
Date: 28 Aug 2006 18:06:06 -0400
Organization: SBC http://yahoo.sbc.com
Sender: cppm...@netlab.cs.rpi.edu
Message-ID: <bKIIg.4386$q63.2510@newssvr13.news.prodigy.com>
X-Original-Date: Mon, 28 Aug 2006 20:54:31 GMT
X-Submission-Address: c++-sub...@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
                iQBVAwUARPNo1EHMCo9UcraBAQELQgH/cW7H8J9ls2vFhLxFwF/WnJ37kgshkaU8
                zRSEidyXePZlHr4gG8p6bvdxluExIVYA23CYhIHvHj45VI9OTV6n9A==
                =Cgzy
Approved: c.l....@bazarov.com
Lines: 98
NNTP-Posting-Host: 65.182.171.162
X-Trace: sv3-rlg5ouGA4I7fY8sMM2fTMdSm9KKKlX+hM6qbewIBloPpkakUgcrM1ZwgvY/yhQnuBdvvEA9DsbI27AY!khEiFuwk6gkWKzv1TN1suXyNIUTDCTU0aS9HcZVa/ddWHeVpxbxMfzJWuJAkAiOBbCKwHc3jWbMp!jEPaQMuHBThGfPWpHUP/ASIfA0u6dYSY6w==
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: ab...@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32

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( )
      {
        printf( " D::N1::N2::f( )\n" );
        ( ( B< int >::N1::N2* ) this )->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 
compiler just generates code that instead calls D::N1::N2::f( ) recursively.

What am I doning wrong?  How can I call the base's f( )?

Thanks for any help you can offer!

- Roger


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google