home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!utcsri!relay.cs.toronto.edu!compuserve.com!76336.3114
- Newsgroups: comp.lang.c++
- From: 76336.3114@CompuServe.COM (Kevin Dean)
- Subject: Private base classes
- Message-ID: <921213165900_76336.3114_EHJ32-2@CompuServe.COM>
- Date: 13 Dec 92 17:03:15 GMT
- Lines: 41
-
- I tried to do the following in Borland C++:
-
- class A {};
- class B : private A {};
- class C1 : public B, public A {};
-
- BC++ naturally warned me about A being both a direct and indirect base
- class of C1 and so refused to compile it. I was able to get around the
- problem:
-
- class CA : public A {};
- class C2 : public B, public CA {};
-
- My first thought, however, was that the declaration of C1 should have
- been allowed. If A is a private base class of B, no class derived from B
- can access A so there should be no ambiguity in accessing members of A
- from C1: the only A visible is the direct base class of C1.
-
- This leads to an interesting hole in the C++ programming paradigm. A
- class derived from B has no access to or knowledge of the private portion
- of B (I'm ignoring friendship here). Up until now, I have always believed
- that, as long as the public and protected interfaces don't change, I can
- do whatever I like with the implementation of B, including changing its
- private interface. If, as I did in this case, I decide that B (and other
- related classes) can be better implemented with A as a private base, I
- need to know everything about classes derived from B so that I can be sure
- that everything will compile. In other words, I need to have forward
- knowledge of all classes that are or could be derived from B. Similarly,
- I need to know more about B than just its public and protected interfaces;
- I need to know what its private base classes are before I can reliably use
- it as a base class.
-
- Any thoughts?
-
- Kevin Dean
-
- SNAG: acronym for Sensitive New-Age Goof, one who, usually without any
- relevant experience, is always willing to enlighten the ignorant masses
- on the social issue of the day. Have you hit any SNAGs lately?
-
-
-