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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,635cd9622b25ae59 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!i40g2000cwc.googlegroups.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: Type safety, C++ and code generation Date: 2 May 2006 06:33:17 -0700 Organization: http://groups.google.com Message-ID: <1146576797.106931.267280@i40g2000cwc.googlegroups.com> References: <1146143954.169807.207080@t31g2000cwb.googlegroups.com> <1146148380.102042.119860@y43g2000cwc.googlegroups.com> <2051047.MTAq1HeU7p@linux1.krischik.com> NNTP-Posting-Host: 192.91.173.42 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1146576803 1783 127.0.0.1 (2 May 2006 13:33:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 2 May 2006 13:33:23 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: i40g2000cwc.googlegroups.com; posting-host=192.91.173.42; posting-account=lnUIyw0AAACoRB2fMF2SFTIilm8F10q2 Xref: g2news2.google.com comp.lang.ada:4013 Date: 2006-05-02T06:33:17-07:00 List-Id: Maciej Sobczak wrote: > Martin Krischik wrote: > > >>What about making different types really distinct? > >> > >>typedef ranged_type R1; > >>typedef ranged_type R2; > >>typedef ranged_type R3; > >> > >> > >>Above, R1 and R2 are equal to the compiler > > > This is because "typdef" in C++ is "subtype" in Ada. > > Not really - you cannot add constraints with typedef. ;) > > > You would need: > > > > class R1 : ranged_type {}; > > class R2 : ranged_type {}; > > class R3 : ranged_type {}; > > > > to create new types. > > Except that those new types would be problematic to use with operations > that are already defined for ranged_type (especially those which return > ranged_type), because there is no implicit conversion to the derived class. > That's not true. operators are usually defined using references. A reference to a child class is alway implicitly convertable to a reference to its parent class. The only issues with the above are: 1) it should use public inheritance, not private to allow the user access to any member function that may be defined (i.e., member operators). 2) it has no constructors, because they are not inherited. 3) assigning the result back to an object of the child class requires a constructor to be defined. REH