From -460074417544705972
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,72474552f2914242,start
X-Google-Attributes: gidf78e5,public
From: Wolfgang Bangerth <wolf@gaia.iwr.uni-heidelberg.de>
Subject: Class inheritance and explicit specialization
Date: 1998/04/06
Message-ID: <Pine.GSO.3.96.980406165737.14653A-100000@nike>#1/1
X-Deja-AN: 341415113
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
X-Original-Date: Mon, 6 Apr 1998 17:18:29 +0200 (MET DST)
MIME-Version: 1.0
X-Sender: wolf@nike
Content-Type: TEXT/PLAIN; charset=US-ASCII
Organization: -
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANSkVfuEDnX0m9pzZAQG39gF6A3lt7DzAuOM1b9xkdGvpf/AL/uk+DxM3 fViqB/yMWx66Hz0jubKd20va8gUNuK+j =yvkz
Newsgroups: comp.std.c++


Consider the following class hierarchy:

  template <int N>
  class Base {...};

  class Base<1> {...};


  template <int N>
  class Derived : public Base<N> {...};

Now, I ask myself whether an object of type Derived<1> would be derived
from the explicitely specialized class Base<1> or maybe if Derived<1> is
not declared unless I explicitely specialize it? I would assume that it be
the first possibility, but after some consideration I am not so sure
anymore.

The question is triggered by the following: if I have the classes

  template <int N>
  class X    { void f(); };

  class X<1> { void f(); };

then defining the template

  template <int N> void X<N>::f () {...}

refers only to the function of the general template, not to X<1>::f. If I
wanted to use the latter, I have to give an explicitely specialized
version. I consider this to be a mis-feature of the standard an use the
following workaround: put all functions which differ in implementation in
the classes Base<1>, Base<2>, ..., whereas all functions which can be
implemented in the same way independant of N are put in Derived<N>. This,
however relies upon the abovementioned feature that Derived<1> is really
derived of Base<1>, etc.

I have looked into the draft standard, but found nothing really referring
to this case. Also the recently published ARM, 3rd edition does not 
mention this in detail, though I get the impression that my view may be
right when reading it.

Thanks for any clarifications on the subject,
-- Wolfgang


(By the way: gcc 2.8 and egcs both have a bug in that they look up members
of base classes of Derived<N> in Base<N>, even if N==1, i.e. you will get
a problem when using Derived<1> if Base<1> has another object layout than
Base<N>, since the compiler then will look at wrong addresses for member
variables of Base<1>. This bug is reported. There is also a workaround
for some simple cases. gcc 2.7 works correctly on this kind of class
hierarchies.)



--------------------------------------------------------------------------
Wolfgang Bangerth                          wolf@gaia.iwr.uni-heidelberg.de



--Drove_of_Donkeys_893_000--
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



