From 176294717719480933
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: "Andrei Alexandrescu" <alexandrescua@micromodeling.com>
Subject: Re: Protected Inheritance
Date: 1999/02/05
Message-ID: <36b9fd49.0@10.1.1.65>#1/1
X-Deja-AN: 441053746
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> <HEbu2.18017$202.8772558@news1.teleport.com>
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Original-Date: 5 Feb 1999 12:12:25 -0500
X-Complaints-To: news@news.unimelb.edu.au
X-Approved-For-Group: jep@eagle.lhup.edu comp.lang.c++.moderated
X-Trace: izvestia.its.unimelb.edu.au 918234886 30388 128.250.29.17 (5 Feb 1999 17:14:46 GMT)
Organization: unknown
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANrsm4uEDnX0m9pzZAQHcUwF/RK8MiaFgbIXD9ZGP2PwF9yDMMDbUkbI9 keIqlc+7Xpr+uEeYHnRyNeklrCvTIs9G =Z7sE
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: 5 Feb 1999 17:14:46 GMT
Newsgroups: comp.std.c++,comp.lang.c++.moderated

Scott Meyers wrote in message ...
[snip]
>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.
[snip]

I don't want to look like evangelizing VC6, but here it's not its problem.
The "final class" C++ idiom is:

class DontDeriveFromSomething
{
    friend class Something;
    DontDeriveFromSomething() {}
};

class Something : virtual public DontDeriveFromSomething
{
public:
    Something() {}
};

class SomethingElse : public Something
{
};

SomethingElse s;    // compile-time error

Please note that the name of the very base class is important, because it
will appear in the error message, which otherwise is not very informative.

By the way, I tried to templatize the idiom, and I thought it should work.
But VC5 chokes ignores the case when the template parameter is made a friend
of the template class. Who's wrong? Here's the code:

template <class T>
class DontDeriveFromMyTemplateParameter
{
    friend class T;
    DontDeriveFromMyTemplateParameter() {}
};

class Something : virtual public
DontDeriveFromMyTemplateParameter<Something>
{
public:
    Something() {}    // compile-time error here???
};

class SomethingElse : public Something
{
};

SomethingElse s;

As of the protected inheritance issue, I also look forward to seeing a sound
conceptual definition of it.

Andrei

P.S. Nice to see you on clcm again.



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



