Thread View: comp.std.c++
2 messages
2 total messages
Started by Herb Sutter
Wed, 06 Dec 1995 18:44
Protected Inheritance: ?
Author: Herb Sutter
Date: Wed, 06 Dec 1995 18:44
Date: Wed, 06 Dec 1995 18:44
62 lines
3378 bytes
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. ]
Re: Protected Inheritance: ?
Author: Steve Clamage
Date: Thu, 07 Dec 1995 18:37
Date: Thu, 07 Dec 1995 18:37
33 lines
1605 bytes
1605 bytes
In article c95@steel.interlog.com, herbs@interlog.com (Herb Sutter) writes: > >"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. The only reason for protected inheritance I ever saw or heard was for symmetry and because there seemed to be no reason to disallow it. >... In >contrast, I've recently come upon two detailed examples in my own work where >it is both necessary and elegant. ... >If the above literature really reflects the state of the industry, I should >write a few articles. Please do. I always find it a bit embarassing when teaching C++ to describe protected inheritance as a solution in search of a problem. --- Steve Clamage, stephen.clamage@eng.sun.com --- [ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads