home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18348 < prev    next >
Encoding:
Text File  |  1992-12-23  |  3.2 KB  |  78 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pmafire!news.dell.com!natinst.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Virtual base classes
  5. Message-ID: <1992Dec23.154929.7674@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <724475492snx@trmphrst.demon.co.uk> <449@genie.UUCP>
  10. Date: Wed, 23 Dec 1992 15:49:29 GMT
  11. Lines: 65
  12.  
  13. In article <449@genie.UUCP> roger@genie.UUCP (Roger H. Scott) writes:
  14. >In article <724475492snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk writes:
  15. >>In article <445@genie.UUCP> roger@genie.UUCP (Roger H. Scott) writes:
  16. >>> If Kludge is a non-public subclass of WellFormed then there
  17.  
  18.     Please say 'base' and 'derived' or you'll confuse me. 
  19. I assume you mean that WellFormed is a private base of Kludge?
  20.  
  21. >>> isn't much point in talking about Kludge redefining WellFormed's virtual
  22. >>> functions since you can't use a Kludge in a place where a WellFormed is
  23. >>> expected (i.e., who would ever have hold of a Kludge and send it one of
  24. >>> WellFormed'd messages, other than a member function of Kludge?).
  25. >>
  26. >>Imagine that WellFormed's constructor adds all WellFormeds to some 
  27. >>Collection of WellFormeds. Notice that all Kludges will also be added to 
  28. >>this collection. Now imagine some calling some virtual function for all 
  29. >>WellFormeds in the Collection.
  30. >
  31. >This seems to raise an interesting question: does there exist an Is-A
  32. >relationship between Kludge and WellFormed, 
  33.  
  34.     If this was intended, Kludge should have been derived
  35. using public virtual inheritance:
  36.  
  37.     class Kludge : public virtual WellFormed { ..
  38.  
  39. >and if not, what does it mean to
  40. >have a collection of objects that *claim* to be WellFormeds but are in fact
  41. >Kludges?  
  42.  
  43.     If we have
  44.  
  45.     class Kludge : private WellFormed { ...
  46.  
  47. it is not so easy to obtain a pointer to the WellFormed to put
  48. in the collection. In particular, a cast by the public wont work 
  49. because WellFormed is a private base. 
  50. Given that WelFormed is closed and locked away in
  51. the library, how would Kludge get access to the WellFormed subobjects
  52. address?
  53.  
  54.     Can Kludge perform the cast?
  55.  
  56.     WellFormed *Kludge::GetWellFormed()const 
  57.         { return (WellFormed*)this;}
  58.     // legal ??
  59.  
  60. >Do we see a small whole in the type system here, where within
  61. >member functions inherited from a non-public base class an object which
  62. >is in fact a Kludge can be used interchangably with an object that is a
  63. >WellFormed (the example cited by Nikki uses the base class's constructor, but
  64. >any member function of the base class will do)?  I'd like to see some sort
  65. >of comprehensive statement about the (intended? actual?) semantics of non-
  66. >public inheritance in C++.
  67.  
  68.     The statement is just the ARM. For a critique try
  69.  
  70. "A Critique of the Inheritance Principles of C++" by
  71. Markku Sakinnen, Computing Systems Vol 5 No 1.
  72.  
  73. -- 
  74. ;----------------------------------------------------------------------
  75.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  76.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  77. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  78.