From 3147677525147458737
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc772,ef0c226459c03bdf
X-Google-Attributes: gidfc772,public
X-Google-Thread: f78e5,edd477ec92e5348f,start
X-Google-Attributes: gidf78e5,public
From: "Scott Meyers" <smeyers@aristeia.com>
Subject: Re: Protected Inheritance
Date: 1999/02/04
Message-ID: <HEbu2.18017$202.8772558@news1.teleport.com>#1/1
X-Deja-AN: 440645094
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <Pine.GSO.3.95-960729.990131142619.5694B-100000@finan.ncl.ac.uk> <slrn7bbi9a.q1a.sbnaran@localhost.localdomain> <sUPt2.16333$202.8056314@news1.teleport.com> <79aesq$qlr$1@uuneo.neosoft.com>
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Original-Date: 4 Feb 1999 09:53:40 -0500
X-Complaints-To: news@news.unimelb.edu.au
X-Approved-For-Group: hsutter@peerdirect.com comp.lang.c++.moderated
X-Trace: izvestia.its.unimelb.edu.au 918147696 18375 128.250.29.16 (4 Feb 1999 17:01:36 GMT)
Organization: unknown
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANrnSQOEDnX0m9pzZAQF1VwF/bqvbN53ubhVhjcfd5ARY2VnpJ59E0uZU BarpyhTM1t903kkPvjA59yE/31eOGpA5 =vx5F
X-WARNING-TO-MODERATORS: This article has been processed and accepted using a cryptographic program by the moderator of comp.lang.c++.moderated. Its content must not be changed or it will be automatically cancelled. If you don't like the article or its crossposting, return it to the submitter.  (You can delete this message if you are the last moderator to see it.)
NNTP-Posting-Date: 4 Feb 1999 17:01:36 GMT
Newsgroups: comp.std.c++,comp.lang.c++.moderated

[I've included comp.std.c++ for reasons that should be obvious...]

Bill Wade <bill.wade@stoner.com> wrote in message
news:79aesq$qlr$1@uuneo.neosoft.com...

>Consider a reference counting base class, RefCnt.  In an MI hierarchy,
>reference counted objects will probably use public virtual inheritance
>from RefCnt.
>
>For development purposes I may want to monitor the RefCnt behavior of
some
>classes (perhaps I suspect I'm leaving "dead" circles of references
>somewhere).  I can make a mixin class DbgRefCnt, which also virtually
>inherits from RefCnt, to tell me what is going on.
>
>DbgRefCnt is probably not part of the public interface of the classes
that
>use it.  It is a temporary implementation detail.  As such, classes
would
>normally use private inheritance.  However I really only want at most
one
>DbgRefCnt object per RefCnt object.  This means that I should use
virtual
>inheritance for DbgRefCnt.  If I use virtual private inheritance I lose
>the ability for further derivation (constructor of DbgRefCnt is not
>accessible to further derived classes).  For this case it would seem
>appropriate to use protected inheritance.

This might be a reasonable example, but I'm not convinced C++ works the
way
you describe.  In particular, I don't think further derivation is
supposed
to be prohibited by the use of private virtual inheritance.  I fed this
to
VC6:

  class Base {
  public:
    Base();
  };

  class Derived: private virtual Base {};

  class MoreDerived: public Derived {};

  MoreDerived m;

It took it without complaint.  Since we all know VC6 is a perfect
compiler,
this should settle the matter.  Ahem.  The FDIS (and presumably the
standard -- I really should buy a copy, shouldn't I?) addresses the
matter
in 12.6.2.  Paragraph 2 seems to back you up (I've omitted stuff that
doesn't seem germane here):

  1 In the definition of a  constructor  for  a  class,  initializers
for
    direct  and  virtual base subobjects and nonstatic data members can
be
    specified by a ctor-initializer, which has the form
       ctor-initializer:
               : mem-initializer-list
       mem-initializer-list:
               mem-initializer
               mem-initializer , mem-initializer-list
       mem-initializer:
               mem-initializer-id ( expression-listopt )
       mem-initializer-id:
               ::opt nested-name-specifieropt class-name
               identifier

  2 Names in a mem-initializer-id are looked up in the scope of  the
con-
    structor's class and, if not found in that scope, are looked up in
the
    scope containing the constructor's definition.

However, let us not forget that constructors don't have names (12.1,
para
1).  So I'm not quite sure how to interpret the above.

Does 12.6.2 really mean that private virtual base classes may be
initialized only by their immediate descendant classes (excluding
friendship issues)?

Scott

Scott Meyers, Ph.D.                  Voice: 503/638-6028
Author:  Effective C++ CD            Fax:   503/638-6614
         Effective C++               Email: smeyers@aristeia.com
         More Effective C++          WWW:   http://www.aristeia.com/





      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]



