home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18086 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.3 KB  |  56 lines

  1. Path: sparky!uunet!utcsri!relay.cs.toronto.edu!compuserve.com!76336.3114
  2. Newsgroups: comp.lang.c++
  3. From: 76336.3114@CompuServe.COM (Kevin Dean)
  4. Subject: Private base classes
  5. Message-ID: <921216205429_76336.3114_EHJ34-2@CompuServe.COM>
  6. Date: 16 Dec 92 21:06:02 GMT
  7. Lines: 47
  8.  
  9. In the excitement generated by the fact that someone had managed to post
  10. to comp.lang.c++ from CompuServe, the intent of my original posting was
  11. lost.  Here it is again:
  12.  
  13. I tried to do the following:
  14.  
  15. class A {};
  16. class B : private A {};
  17. class C1 : public B, public A {};
  18.  
  19. My compiler naturally warned me about A being both a direct and indirect
  20. base class of C1 and so refused to compile it.  I was able to get around
  21. the problem:
  22.  
  23. class CA : public A {};
  24. class C2 : public B, public CA {};
  25.  
  26. My first thought, however, was that the declaration of C1 should have
  27. been allowed.  If A is a private base class of B, no class derived from B
  28. can access A so there should be no ambiguity in accessing members of A
  29. from C1: the only A visible is the direct base class of C1.
  30.  
  31. This leads to an interesting hole in the C++ programming paradigm.  A
  32. class derived from B has no access to or knowledge of the private portion
  33. of B (I'm ignoring friendship here).  Up until now, I have always believed
  34. that, as long as the public and protected interfaces don't change, I can
  35. do whatever I like with the implementation of B, including changing its
  36. private interface.  If, as I did in this case, I decide that B (and other
  37. related classes) can be better implemented with A as a private base, I
  38. need to know everything about classes derived from B so that I can be sure
  39. that everything will compile.  In other words, I need to have forward
  40. knowledge of all classes that are or could be derived from B.  Similarly,
  41. I need to know more about B than just its public and protected interfaces;
  42. I need to know what its private base classes are before I can reliably use
  43. it as a base class.  (I am not debating the need here for multiple
  44. inheritance; I may have a genuine need for two instances of A.  What I am
  45. debating is the semantics of private vs. public or protected.)
  46.  
  47. Any thoughts?
  48.  
  49. Kevin Dean
  50.  
  51. SNAG: acronym for Sensitive New-Age Goof, one who, usually without any
  52. relevant experience, is always willing to enlighten the ignorant masses
  53. on the social issue of the day.  Have you hit any SNAGs lately?
  54.  
  55.  
  56.