From 3940770712758158891
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc772,ef0c226459c03bdf
X-Google-Attributes: gidfc772,public
X-Google-Thread: f78e5,edd477ec92e5348f
X-Google-Attributes: gidf78e5,public
From: smeyers@aristeia.com (Scott Meyers)
Subject: Re: Protected Inheritance
Date: 1999/02/17
Message-ID: <MPG.1133baa8d2e9d7b1989684@news.teleport.com>#1/1
X-Deja-AN: 446350363
Approved: daveed@vandevoorde.com
Sender: cppmods@netlab.cs.rpi.edu
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> <HEbu2.18017$202.8772558@news1.teleport.com> <36b9fd49.0@10.1.1.65> <AwGu2.19901$202.9740872@news1.teleport.com> <36C046BE.4233@clipper.ens.fr>
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Approved-For-Group: stephen.clamage@sun.com comp.std.c++
X-Original-Date: Tue, 16 Feb 1999 17:26:52 -0800
Organization: unknown
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUANspc8UHMCo9UcraBAQHSsQH/fAnKayha7tVbza/cHFE8HnSmu5PPDqhf LVH/DHaRgX2LkqxU4ZPgToa1M4jFdVH04dQmbkmHRYmzyVp1GODbRg== =OQFK
Newsgroups: comp.std.c++,comp.lang.c++.moderated

In article <36C046BE.4233@clipper.ens.fr>, bonnard@clipper.ens.fr says...
> Scott Meyers wrote:
> 
> > True, but don't forget the copy constructor:
> > 
> >   class MoreDerived: public Something {
> >   public:
> >     MoreDerived()
> >     : Something(*new Something) {}   // initialize DontDeriveFromSomething
> >   };                                 // via copy ctor
> 
> Could you explain why you think that it should work ?

It should work because the virtual base class has an implicit public copy
constructor, so a more derived class could initialize
DontDeriveFromSomething via this constructor.  Alas, that's not what the
code snippet above does.  This is the correct code:

  class MoreDerived: public Something {
  public:
    MoreDerived()
    : DontDeriveFromSomething(*new Something) {}
  };

To prevent this, DontDerivedFromSomething needs to declare its copy
constructor private.

> > >By the way, I tried to templatize the idiom, and I thought it should work.
> > 
> > I think it should, too.
> 
> No, sadly it won't, because of some strange [moderators, I can say stupid
> ?]  rule in the standard, which prohibits making template parameters
> friends.

Can somebody summarize for me the motivation behind this rule?  If, as I
suspect, this has already been hashed to death in this newsgroup, feel free
to just point me to a subject thread I can look up at Deja News.

Thanks,

Scott

-- 
Scott Meyers, Ph.D.                  smeyers@aristeia.com
Software Development Consultant      http://www.aristeia.com/
Visit http://meyerscd.awl.com/ to demo the Effective C++ CD


[ 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              ]


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



