home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17890 < prev    next >
Encoding:
Text File  |  1992-12-13  |  2.0 KB  |  50 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: <921213165900_76336.3114_EHJ32-2@CompuServe.COM>
  6. Date: 13 Dec 92 17:03:15 GMT
  7. Lines: 41
  8.  
  9. I tried to do the following in Borland C++:
  10.  
  11. class A {};
  12. class B : private A {};
  13. class C1 : public B, public A {};
  14.  
  15. BC++ naturally warned me about A being both a direct and indirect base
  16. class of C1 and so refused to compile it.  I was able to get around the
  17. problem:
  18.  
  19. class CA : public A {};
  20. class C2 : public B, public CA {};
  21.  
  22. My first thought, however, was that the declaration of C1 should have
  23. been allowed.  If A is a private base class of B, no class derived from B
  24. can access A so there should be no ambiguity in accessing members of A
  25. from C1: the only A visible is the direct base class of C1.
  26.  
  27. This leads to an interesting hole in the C++ programming paradigm.  A
  28. class derived from B has no access to or knowledge of the private portion
  29. of B (I'm ignoring friendship here).  Up until now, I have always believed
  30. that, as long as the public and protected interfaces don't change, I can
  31. do whatever I like with the implementation of B, including changing its
  32. private interface.  If, as I did in this case, I decide that B (and other
  33. related classes) can be better implemented with A as a private base, I
  34. need to know everything about classes derived from B so that I can be sure
  35. that everything will compile.  In other words, I need to have forward
  36. knowledge of all classes that are or could be derived from B.  Similarly,
  37. I need to know more about B than just its public and protected interfaces;
  38. I need to know what its private base classes are before I can reliably use
  39. it as a base class.
  40.  
  41. Any thoughts?
  42.  
  43. Kevin Dean
  44.  
  45. SNAG: acronym for Sensitive New-Age Goof, one who, usually without any
  46. relevant experience, is always willing to enlighten the ignorant masses
  47. on the social issue of the day.  Have you hit any SNAGs lately?
  48.  
  49.  
  50.