home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Proposal - enhancement for switch statement.
- Message-ID: <1992Nov16.150331.11996@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Nov15.190830.11622@cssc-syd.tansu.com.au>
- Date: Mon, 16 Nov 1992 15:03:31 GMT
- Lines: 51
-
- In article <1992Nov15.190830.11622@cssc-syd.tansu.com.au> pete@cssc-syd.tansu.com.au (Peter Alexander Merel) writes:
- >Before I describe what occurred to me, yes folks I know that a switch is not
- >as useful as a virtual function.
-
- Not so. Switches and virtual functions have entirely different
- purposes. Switches are correctly used for selecting amoung a set of options,
- virtuals perform an indeterminate operation (I actually mean 'late bound').
-
-
- The switch is the *correct* form to use to discriminate
- from a finite set of possibilities which are known in advance.
- Virtuals are used for completely unknown possibilities not known
- until run-time.
-
-
- This is why type selection for heterogeneous aggregates
- should use switches. :-)
- >
- >But what I'd like for a snippet I'm working on at the moment would be for
- >switch to use operator== rather than relying on conversion to int, so that
- >I could use it to test cases on objects rather than building an industrial
- >strength if statement.
-
- You can always write
-
- T x=expr;
- if(x==case1){..}
- else if(x==case1){ ..}
- ...
- else { ..}
-
- which is better structured than a switch anyhow. For switches I would
- like
-
- switch (i) {
- case 1..10: ... break;
- case 20,25,30: ... break;
-
- Pascal did the switch better.
-
- >
- >Any chance?
- >
-
- Doubt it. How about case 1..10: ?? Any chance? Probably not.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-