🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2884

Protected Inheritance: ?

#2884
From: Herb Sutter
Date: Wed, 06 Dec 1995 18:44
62 lines
3378 bytes

"What is protected inheritance?"

Through experience, I now know the answer.  However, by far the most common 
(and wrong) idea I keep hearing is that it was 'put in for completeness' since 
we already have public and private inheritance, but that no one really knows 
what it's good for.  All the major books barely mention it.  In more or less 
chronological order:

Meyers ("Effective C++", 1992) says only: "no one seems to know what protected 
inheritance (a latecomer on the scene anyway) is supposed to mean." (pg 120)

Stroustrup (D&E, 1994) has only "inheritance, public" and "inheritance, 
private" in the index.

Ellis and Stroustrup (ARM, 1994 reprint) give it two lines in Section 19, 
informing that the committees have voted it in.  The same two lines are given 
in Stroustrup (C++PL2, 1993) section a.1.  I can't find even an index entry in 
other books around this period, such as Coplien ("Advanced C++", 1992).

Carroll and Ellis ("Designing and Coding Reusable C++", 1995) says only: "(You 
might notice that we do not discuss protected derivation.  Whether protected 
derivation is useful is debatable.)" (pg 49)

The best I've found is Cline's and Lomow's ("C++ FAQs", 1995) brief mention in 
their book's FAQ #449, saying that protected inheritance is for when you want 
further-derived classes to have access to the base class' protected interface. 
 Fine, that's part of it, and there are no examples and no further English 
discussion of "what protected inheritance means" and when you'd use it.  In 
contrast, I've recently come upon two detailed examples in my own work where 
it is both necessary and elegant.

Here's the upshot and my question(s): For what specific reasons did the 
standards committees include protected inheritance?  Was it only for 
completeness, or were specific examples where protected inheritance was 
necessary known at the time?  On a wider note, hasn't anyone else come across 
situations where protected inheritance was The Right Thing To Do(tm)?  While 
it's true that its use is rare, I find it hard to believe that I should be the 
only one to come across such design situations.

If the above literature really reflects the state of the industry, I should 
write a few articles.  However, before I start wasting time on that, I'd 
rather find out that protected inheritance is after all understood, but just 
somehow hasn't made it into the literature.

Thanks in advance,

Herb


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter (herbs@connobj.com)

Connected Object Solutions     2228 Urwin - Suite 102     voice 416-618-0184
http://www.connobj.com/      Oakville ON Canada L6L 2T2     fax 905-847-6019


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <4a4hh6$c95@steel.interlog.com>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: herbs@interlog.com (Herb Sutter)
Newsgroups: comp.std.c++
Subject: Protected Inheritance: ?
Date: 06 Dec 1995 18:44:53 GMT
Organization: Connected Object Solutions (div of Daystar Software Systems Design Inc.)
Approved: Matt@Austern
Message-ID: <4a4hh6$c95@steel.interlog.com>
NNTP-Posting-Host: austern.hip.berkeley.edu