home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11682 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  2.0 KB

  1. Xref: sparky comp.lang.c++:11682 comp.std.c++:977
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!mips!mips!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
  6. Message-ID: <1992Jul28.183746.24287@ucc.su.OZ.AU>
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <1992Jul24.234628.21196@cadsun.corp.mot.com> <1992Jul25.172045.24675@ucc.su.OZ.AU> <BryL9q.K5I@watcgl.waterloo.edu>
  11. Date: Tue, 28 Jul 1992 18:37:46 GMT
  12. Lines: 41
  13.  
  14. In article <BryL9q.K5I@watcgl.waterloo.edu> rhbartel@watcgl.waterloo.edu (Richard Bartels) writes:
  15. >As long as the downcasting discussion is open again,
  16. >the example we are confronting which requires something like
  17. >that, we think, is the issue of input from disk.
  18. >
  19. >I would love to have a solution that did not require the cop-out of
  20. >isA() and cast/convert.
  21. >
  22. >Consider the classic "List" class and "ListNode" class.
  23. >ListNode is a base class, and assume there are two flavors
  24. >of derived node.  We write a List that contains a mix of
  25. >these nodes out to a file; now we want to read the List back
  26. >in and reconstruct it.
  27. >
  28. >Can it be done without resorting to an isA() member function,
  29. >some member data to identify node type, and possibly some
  30. >casting/conversion?
  31.  
  32.     a) without some type information, it cant be done.
  33.     b) without casting it can (and should :-) be done
  34.  
  35.     union hetero {
  36.         type1 *p1;
  37.         type2 *p2;
  38.     };
  39.  
  40.  
  41. And the list is homogeneous--all the elements are of type 'hetero'.
  42.  
  43. >
  44. >What's the authoritative answer?
  45.  
  46.     Dont know. Who's the authority?
  47.  
  48.  
  49.  
  50. -- 
  51. ;----------------------------------------------------------------------
  52.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  53.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  54. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  55.