Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!world!wmm From: wmm@world.std.com (William M Miller) Newsgroups: comp.std.c++ Subject: Re: protected != public-to-derived Message-ID: <1991Mar24.205156.10206@world.std.com> Date: 24 Mar 91 20:51:56 GMT References: <1991Mar19.165333.23908@asc.slb.com> <1991Mar24.010442.27298@kestrel.edu> Organization: The World Public Access UNIX, Brookline, MA Lines: 28 gyro@kestrel.edu (Scott Layson) writes: > I have bumped my head on this rule a couple of times, and frankly > don't agree with the rationale given in E&S for its existence (see the > commentary starting on the bottom of p.254). The last sentence of > that rationale, which describes a bug someone once had which the rule > would have prevented, reads: > > Naturally, the use of a virtual function for performing the update > would have avoided the problem. > > Seems to me that this sentence admits that the bug really had quite > another cause than the mistaken access of a protected member. > > Since the issue has come up, I am very much interested to hear the > committee's current feeling about this rule. I can't speak for the rest of the committee, but I personally think the rationale is pretty reasonable. It might very well be that Derived1 and Derived2 classes have different conventions for managing the protected members of their common base class. If a Derived1 member function were able to access the base class protected members via a pointer or reference to the base class, because of the conversion rules, it might actually be manipulating a Derived2 object in an invalid fashion. By restricting access to use only a Derived1 pointer or reference, you at least have the type system working in your favor to avoid this kind of bug. -- William M. Miller, Glockenspiel, Ltd.; vice chair, X3J16 wmm@world.std.com