home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12362 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  2.1 KB

  1. Path: sparky!uunet!usc!elroy.jpl.nasa.gov!swrinde!mips!mips!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  2. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Downcasting (was: Re: run-time type checking)
  5. Message-ID: <1992Aug15.000101.8975@ucc.su.OZ.AU>
  6. Date: 15 Aug 92 00:01:01 GMT
  7. References: <9222518.29381@mulga.cs.mu.OZ.AU> <4820@holden.lulea.trab.se> <9222715.29197@mulga.cs.mu.OZ.AU>
  8. Sender: news@ucc.su.OZ.AU
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. Lines: 44
  11. Nntp-Posting-Host: extro.ucc.su.oz.au
  12.  
  13. In article <9222715.29197@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  14. >jbn@lulea.trab.se (Johan Bengtsson) writes:
  15. >
  16. >>maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  17. >>:
  18. >>:There are other ways than tagged pointers to make downcasting
  19. >>:sound. One might be to declare the derived classes that you want
  20. >
  21. >If I pass you a Base*, I expect that you will only be able to modify it
  22. >using the Base interface. Thus if you want to be able to modify it using
  23. >the Derived interface, then the conversion from Base* to Derived* should
  24. >be an explicit part of the Base interface.
  25. >
  26. >The real drawback is the amount of typing required. This can be reduced
  27. >with macros if desired.
  28. >
  29.  
  30.     Or with tagged pointers. They're meant to optimise the
  31. typing down to the amount needed and no more, excepting for
  32. the interface declarations.
  33.  
  34.     [A,B,C]*p;
  35.     p->print();
  36.  
  37. Calls A::print(), B::print(), C::print() depending. Even less
  38. typing than for the downcasting proposal. Indeed, one of the
  39. criticisms of tagged pointers is that REAMS AND REAMS of code
  40. can be generated by the compiler from a few simple uses.
  41.  
  42.     [A,B,C,D,E] *a, *b, *c;
  43.  
  44.     f(a,b,c);
  45.  
  46. Generates switches to call up to 625 different cases. If f
  47. is a template function, all 625 cases of the function will be
  48. created as well!
  49.  
  50.  
  51.  
  52. -- 
  53. ;----------------------------------------------------------------------
  54.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  55.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  56. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  57.