From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1cf653444208df72 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-08 10:05:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!feed.textport.net!out.nntp.be!propagator-SanJose!news-in-sanjose!newsfeed.mathworks.com!cyclone.swbell.net!pln-e!spln!dex!extra.newsguy.com!newsp.newsguy.com!drn From: Robert*@ Newsgroups: comp.lang.ada Subject: Re: ada vs. cpp Date: 8 Oct 2001 09:34:14 -0700 Organization: Newsguy News Service [http://newsguy.com] Message-ID: <9pski60j31@drn.newsguy.com> References: <9pgr68$7pu1@news.cis.okstate.edu> <9phnic$9g5$1@nh.pace.co.uk> <5fkv7.134136$w7.19988807@news02.optonline.net> NNTP-Posting-Host: p-548.newsdawg.com X-Newsreader: Direct Read News 2.90 Xref: archiver1.google.com comp.lang.ada:13942 Date: 2001-10-08T09:34:14-07:00 List-Id: In article , "Mike says... > >> >> subtype Code is Positive range 1 .. 4; >> subtype Arg is Positive range 6 .. 8; >> >> V2 : constant String := V1 (Arg) & '-' & V1 (Code); >const string V1 = "0123/zzz"; >const string V2 = V1.substr(0, 4) + "-" + V1.substr(5,7); > >Even though your efforts to describe something easy for Ada >and hard for C++ have failed, you should know that I can play >these C++-strings-can-do-this-in-2-lines-and-Ada-can't >games as well. > The difference is that in Ada the range itself is a separate type declaration. So, one can change the range type in one place and have it propgate all over. With your attempt, you hardcoded the range using magic numbers in the variable declaration itself, so if the same range is to be used somewhere else in the code, or in different variable declaration, you need to type it there too manually. There is nothing equivelant in C++ to declaring a new type integer with restricted range. It is simply not in the C++ language.