home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16385 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.2 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!sol.ctr.columbia.edu!usc!rpi!batcomputer!munnari.oz.au!mel.dit.csiro.au!mineng.dmpe.CSIRO.AU!dmssyd.syd.dms.CSIRO.AU!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Proposal - enhancement for switch statement.
  5. Message-ID: <1992Nov16.150331.11996@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: <1992Nov15.190830.11622@cssc-syd.tansu.com.au>
  10. Date: Mon, 16 Nov 1992 15:03:31 GMT
  11. Lines: 51
  12.  
  13. In article <1992Nov15.190830.11622@cssc-syd.tansu.com.au> pete@cssc-syd.tansu.com.au (Peter Alexander Merel) writes:
  14. >Before I describe what occurred to me, yes folks I know that a switch is not
  15. >as useful as a virtual function.
  16.  
  17.     Not so. Switches and virtual functions have entirely different
  18. purposes. Switches are correctly used for selecting amoung a set of options,
  19. virtuals perform an indeterminate operation (I actually mean 'late bound').
  20.  
  21.  
  22.     The switch is the *correct* form to use to discriminate
  23. from a finite set of possibilities which are known in advance.
  24. Virtuals are used for completely unknown possibilities not known
  25. until run-time.
  26.  
  27.  
  28.     This is why type selection for heterogeneous aggregates
  29. should use switches. :-)
  30. >
  31. >But what I'd like for a snippet I'm working on at the moment would be for
  32. >switch to use operator== rather than relying on conversion to int, so that 
  33. >I could use it to test cases on objects rather than building an industrial 
  34. >strength if statement. 
  35.  
  36.     You can always write
  37.  
  38.     T x=expr;
  39.     if(x==case1){..}
  40.     else if(x==case1){ ..}
  41.     ...
  42.     else { ..}
  43.  
  44. which is better structured than a switch anyhow. For switches I would
  45. like
  46.  
  47.     switch (i) {
  48.     case 1..10: ... break;
  49.     case 20,25,30: ... break;
  50.  
  51. Pascal did the switch better.
  52.  
  53. >
  54. >Any chance?
  55. >
  56.  
  57.     Doubt it. How about case 1..10: ?? Any chance? Probably not.
  58.  
  59. -- 
  60. ;----------------------------------------------------------------------
  61.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  62.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  63. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  64.